Visual Studio 2019 .NET Core 3 gRpc not generating service files - asp.net-core

I created a simple gRpc server application using the template in Visual Studio 2019. I then created a protobuf file for the server but I cannot get it to generate the corresponding service files.
The protobuf file is:
syntax = "proto3";
option csharp_namespace = "RpcApi";
import "google/protobuf/timestamp.proto";
package API;
service Conferences {
rpc GetAll (GetAllConferencesRequest) returns (GetAllConferencesResponse) {}
rpc Add (AddConferenceRequest) returns (AddConferenceResponse) {}
}
message GetAllConferencesRequest {}
message GetAllConferencesResponse {
repeated Conference Conferences = 1;
}
message AddConferenceRequest {
Conference conferernce = 1;
}
message AddConferenceResponse {
Conference conference = 1;
}
message Conference {
int32 Id = 1;
string Name = 2;
google.protobuf.Timestamp Start = 3;
string Location = 4;
int32 AttendeeTotal = 5;
}
service Proposals {
rpc GetAll (GetAllProposalsRequest) returns (GetAllProposalsResponse) {}
rpc Add (AddProposalRequest) returns (AddProposalResponse) {}
rpc Approve (ApproveRequest) returns (ApproveResponse) {}
}
message GetAllProposalsRequest {
int32 ConferenceId = 1;
}
message GetAllProposalsResponse {
repeated Proposal Proposals = 1;
}
message AddProposalRequest {
Proposal Proposal = 1;
}
message AddProposalResponse {
Proposal Proposal = 1;
}
message ApproveRequest {
int32 Id = 1;
}
message ApproveResponse {
Proposal Proposal = 1;
}
message Proposal {
int32 Id = 1;
int32 ConferenceId = 2;
string Speaker = 3;
string Title = 4;
bool Approved = 5;
}
And the project file is correctly defined:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Protobuf Include="Protos\rpcapi.proto" GrpcServices="Server" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Grpc.AspNetCore" Version="2.23.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="Services\" />
</ItemGroup>
</Project>
Its supposed to generate server-side files whenever the proto file changes but it never generates those files. What is wrong?

It actually works. The files are generated in the obj directory and not the Services directory. If I do Show All Files, I can see them.

Related

Can Exec task in msbuild fail if exitCode = 0 but there is logging to standard error?

I am curious about:
https://learn.microsoft.com/en-us/visualstudio/msbuild/exec-task?view=vs-2019
ExitCode Optional Int32 output read-only parameter.
Specifies the exit code that is provided by the executed command, except that if the task logged any errors, but the process had an exit code of 0 (success), ExitCode is set to -1.
Can msbuild fail on Exec even if process has an exit code of 0 but it logs to standard error?
I tried to make it fail with the following code:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp3
{
class Program
{
static int Main( string[] args )
{
using ( var stdErr = Console.Error )
{
for ( int i = 0; i <= 100; i++ )
{
stdErr.WriteLine( $"Failed to copy attempt {i}." );
System.Threading.Thread.Sleep( 50 );
}
// Close redirected error stream.
Console.Error.Close();
}
return 0;
}
}
}
It is being called as part of a standard props file.
<Target
Name = "IvaraSign"
AfterTargets="CoreBuild"
BeforeTargets="CopyFilesToOutputDirectory" >
<!-- Update version on main output -->
<!-- this works when the solution being compiled is in the dotnet folder. -->
<Exec Command="C:\Users\Derek.Morin\source\repos\ConsoleApp3\bin\Debug\ConsoleApp3.exe"/>
</Target>
When I build in msbuild I can see the error text in the build output but the compiling passes.
Does the MSBuild Exec task search STDOUT for the string "error"?
I was able to duplicate making exec file fail with the following
static int Main( string[] args )
{
using ( var stdErr = Console.Error )
{
stdErr.WriteLine( $#"signtool.exe : error information: ""Error: Store IsDiskFile() failed."" (-2147024864/0x80070020) [d:\work\1\s\common\MAFPlugins\MAFScripting\Contracts\Contracts.csproj]" );
}
Console.WriteLine( "but I'm still going to return 0" );
return 0;
}
The workaround is to use IgnoreStandardErrorWarningFormat="true".
<Exec Command="C:\ConsoleApp3\ConsoleApp3.exe" IgnoreStandardErrorWarningFormat="true" />

Extract key/value pairs js file

Trough msbuild target tag i am copy a file (if exist) to a new target and changing his name (it is working properly):
<!--///////////////////////////Target CopyOldWebConfigJs//////////////////////////////////////////////-->
<Target Name="CopyOldWebConfigJs" Inputs="#(ContentFiltered)" Outputs="%(Identity).Dummy" DependsOnTargets="webConfigJsCase">
<Exec
Command= "copy "D:\p\Deployments\p\\WebPages\web.config.js" "$(AssemblyRoot)\WebPages\web.config.serverCopy.js""
/>
</Target>
<!-- New target to pre-filter list -->
<Target Name="webConfigJsCase"
Inputs="#(FileToPublish)"
Outputs="%(Identity).Dummy">
<ItemGroup>
<ContentFiltered Include="#(FileToPublish)" Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('%(FileToPublish.Filename)%(FileToPublish.Extension)', 'web.config.js')) AND Exists('D:\\p\\Deployments\\p\\WebPages\\web.config.js')" />
</ItemGroup>
</Target>
<!--///////////////////////////End Target CopyOldWebConfigJs//////////////////////////////////////////////-->
The target file web.config.serverCopy.js is a file that have key/value pair content:
///////////////////////////////// TEST VERSION //////////////////////////////////////////////
//This is used for general web config settings for .js scripts that _webconfig. from staging to production
//It should not be edited or copied
_webconfig = new Object();
_webconfig.env = "pageq03"; // Needs Replacing
_webconfig.deployment = "p"; // Needs Replacing
_webconfig.relativeWebServicePath = "../WS/"; // Needs Replacing
_webconfig.webServiceFileName = "API.asmx"; // Needs Replacing
_webconfig.errorReportingThreshhold = "High"; // Setting for reporting bugs via email. Set to "Low" to report everything. ["Low", "Normal", "High" or "None"]
_webconfig.customPreviewPhaseDuration = 1000; //Setting that controls how long the automatic preview sits and resolves conflicts prior to showing the preview. Higher numbers increase performance while lower numbers enchance user experience.
//_webconfig.NewRelicAppID = {4}; //2805166
//J.A.C.K.A.L. settings (all false by default)
_webconfig.skipBootstrap = false;
_webconfig.skipJqueryUI = false;
_webconfig.skipPOCommon = false;
_webconfig.skipPOCampaignPreviews = false;
_webconfig.skipPOAjaxMonitor = false;
_webconfig.skipIconFonts = false;
_webconfig.skipCookie = false;
_webconfig.skipTouchPunch = false;
_webconfig.skipWebFont = false;
_webconfig.skipJSON = false;
_webconfig.skipKnob = false;
_webconfig.skipGoogleCharts = false;
_webconfig.jqueryuiTheme = "redmond";
//preview scrolling
_webconfig.previewScrollType = "always"; //none | onRender | onChange | Always
_webconfig.previewScrollSpeed = 500; //in milliseconds
//Dyanamic Menu
_webconfig.openMenuLinksInSearch = true;
//WIDGET SETTINGS
_webconfig.masterWidgetPath = "widgets/"; //end '/' required
_webconfig.widgetAnimateResize = false;
_webconfig.widgetAnimateSpeed = 100; //ms
_webconfig.widgetDestroyAnimationSpeed = 900;
_webconfig.widgetDebugModeOn = false;
_webconfig.widgetULIdToUse = "widgetSortable";
_webconfig.widgetToolbarAnchor = "#tblNavigationBar";
_webconfig.widgetFavoritesMiniMenuAnchor = ".navBarRight";
_webconfig.widgetScrollToDuration = 700; //in milliseconds
_webconfig.widgetSelectionIndicatorPhaseDuration = .5; //in seconds
_webconfig.widgetSelectionIndicatorNumOfPhases = 4;
_webconfig.allowUseOfWidgetFavorites = true;
_webconfig.POServicesAppName = "p.PO.Services"; // Needs Replacing
Now after copying it (backup it), I have 2 missions, i need to read his content and
Save the value that _webconfig.deployment holds - that value need to replace the path of the source path CopyOldWebConfigJs target tag Exec commands holds(now it hard-coded) - i don't see how it can be done.
Every key/value that have the phrase // Needs Replacing at the end of it's line, i need to save it's value and insert it's content to other web.config.js on the same directory, with the same structure (same key names).
I am kinda new to MSBUILD and any help with it will be much appreciated..

Read 'hidden' input for CLI Dart app

What's the best way to receive 'hidden' input from a command-line Dart application? For example, in Bash, this is accomplished with:
read -s SOME_VAR
Set io.stdin.echoMode to false:
import 'dart:io' as io;
void main() {
io.stdin.echoMode = false;
String input = io.stdin.readLineSync();
// or
var input;
while(input != 32) {
input = io.stdin.readByteSync();
if(input != 10) print(input);
}
// restore echoMode
io.stdin.echoMode = true;
}
This is a slightly extended version, key differences are that it uses a finally block to ensure the mode is reset if an exception is thrown whilst the code is executing.
The code also uses a waitFor call (only available in dart cli apps) to turn this code into a synchronous call. Given this is a cli command there is no need for the complications that futures bring to the table.
The code also does the classic output of '*' as you type.
If you are doing much cli work the below code is from the dart package I'm working on called dcli. Have a look at the 'ask' method.
https://pub.dev/packages/dcli
String readHidden() {
var line = <int>[];
try {
stdin.echoMode = false;
stdin.lineMode = false;
int char;
do {
char = stdin.readByteSync();
if (char != 10) {
stdout.write('*');
// we must wait for flush as only one flush can be outstanding at a time.
waitFor<void>(stdout.flush());
line.add(char);
}
} while (char != 10);
} finally {
stdin.echoMode = true;
stdin.lineMode = true;
}
// output a newline as we have suppressed it.
print('');
return Encoding.getByName('utf-8').decode(line);
}

Calling a Metro based Security Token Service from an Axis2 STS Client

I want to call a Security Token Service which was created and deployed using Metro 2.2 framework from an Axis 2 STS Client. I'm trying to do the same but getting issues like the one below: -
java.lang.RuntimeException:Incorrect inclusion value: -1
I went deep into the source code and saw that in SecureConversationTokenBuilder class code is wriiten something like this:-
String inclusionValue = attribute.getAttributeValue().trim();
conversationToken.setInclusion(SP11Constants.getInclusionFromAttributeValue(inclusionValue));
then I went into the SP11Constants.getInclusionFromAttributeValue(inclusionValue) and saw the following piece of code:-
public static int getInclusionFromAttributeValue(String value ) {
if (INCLUDE_ALWAYS.equals(value)) {
return SPConstants.INCLUDE_TOEKN_ALWAYS;
} else if (INCLUDE_ALWAYS_TO_RECIPIENT.equals(value)) {
return SPConstants.INCLUDE_TOEKN_ALWAYS_TO_RECIPIENT;
} else if (INCLUDE_NEVER.equals(value)) {
return SPConstants.INCLUDE_TOKEN_NEVER;
} else if (INCLUDE_ONCE.equals(value)) {
return SPConstants.INCLUDE_TOKEN_ONCE;
} else {
return -1;
}
}
as INCLUDE_ALWAYS = "http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Always" which is not equal to what is defined by metro in policy.xml like
http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/Always
Therefore the above code always return -1 and in turn throws a runtime exception as below:-
public void setInclusion(int inclusion) {
if(SPConstants.INCLUDE_TOEKN_ALWAYS == inclusion ||
SPConstants.INCLUDE_TOEKN_ALWAYS_TO_RECIPIENT == inclusion ||
SPConstants.INCLUDE_TOEKN_ALWAYS_TO_INITIATOR == inclusion ||
SPConstants.INCLUDE_TOKEN_NEVER == inclusion ||
SPConstants.INCLUDE_TOKEN_ONCE == inclusion ) {
this.inclusion = inclusion;
} else {
//TODO replace this with a proper (WSSPolicyException) exception
throw new RuntimeException("Incorrect inclusion value: " + inclusion);
}
}
Just wanted to know whether it is possible to get token from Security Token Service (STS) created in Metro Framework invoked from an Axis2 based STS Client.Please advise as I'm stuck in between.
Thanks in advance.

Deploy BrowserFormWebPart declaratively without BinarySerializedWebPart Element

Does anyone know if there is a way to deploy a BrowserFormWebPart (custom InfoPath form for a list content type) using standard AllUsersWebPart element and a CDATA section for the properties? So far I have tried without success. Any help is appreciated.
After 2 days of research - Following code works
private void UpdateInfoPathForms(SPSite oSite)
{
UpdateInfoPath(oSite, "Lists/Audit Calendar/Item/newifs.aspx");
UpdateInfoPath(oSite, "Lists/Audit Calendar/Item/displayifs.aspx");
UpdateInfoPath(oSite, "Lists/Audit Calendar/Item/editifs.aspx");
}
private void UpdateInfoPath(SPSite oSite, string formFileLocation)
{
var file = oSite.RootWeb.GetFile(formFileLocation);
using (SPLimitedWebPartManager manager = file.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared))
{
try
{
var wp1 = new Microsoft.Office.InfoPath.Server.Controls.WebUI.BrowserFormWebPart();
wp1.SubmitBehavior = Microsoft.Office.InfoPath.Server.Controls.WebUI.SubmitBehavior.FormDefault;
wp1.FormLocation = "~list/Item/template.xsn";
wp1.ContentTypeId = oSite.RootWeb.Lists["Audit Calendar"].ContentTypes["Item"].Id.ToString();
IListWebPart listWebpart = wp1 as IListWebPart;
listWebpart.ListId = oSite.RootWeb.Lists["Audit Calendar"].ID;
if (formFileLocation.Contains("newifs.aspx"))
{
listWebpart.PageType = PAGETYPE.PAGE_NEWFORM;
}
else if (formFileLocation.Contains("displayifs.aspx"))
{
wp1.ListFormMode = Microsoft.Office.InfoPath.Server.Controls.WebUI.ListFormMode.ReadOnly;
listWebpart.PageType = PAGETYPE.PAGE_DISPLAYFORM;
}
else if (formFileLocation.Contains("editifs.aspx"))
{
listWebpart.PageType = PAGETYPE.PAGE_EDITFORM;
}
listWebpart.ViewFlags = SPViewFlags.None;
manager.AddWebPart(wp1, "Main", 0);
manager.SaveChanges(wp1);
}
finally
{
manager.Web.Dispose();
}
}
I have had the same problem. Here is what I tried:
<AllUsersWebPart WebPartZoneID="Main" WebPartOrder="2">
<![CDATA[
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="Microsoft.Office.InfoPath.Server.Controls.WebUI.BrowserFormWebPart, Microsoft.Office.InfoPath.Server, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
<importErrorMessage>Cannot import this Web Part.</importErrorMessage>
</metaData>
<data>
<properties>
<property name="ChromeType" type="chrometype">None</property>
<property name="HelpMode" type="helpmode">Modeless</property>
<property name="ChromeState" type="chromestate">Normal</property>
</properties>
</data>
</webPart>
</webParts>]]>
</AllUsersWebPart>
I then have a Feature Receiver that configures the web part:
using (SPLimitedWebPartManager manager = file.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
try
{
BrowserFormWebPart webpart = GetWebPart(manager);
webpart.SubmitBehavior = SubmitBehavior.FormDefault;
webpart.FormLocation = "~list/MyList/template.xsn";
webpart.ContentTypeId = "0x01003C8AD6E14DAD5342BBFAA84E63F8022C";
manager.SaveChanges(webpart);
}
finally
{
manager.Web.Dispose();
}
}
The BrowserFormWebPart properties are required for getting the form to display, but for some reason, setting those properties in the AllUsersWebPart section did not work. The form displays and I can fill it out, but the values from the form do not get inserted into the fields of the list item. I added the following section to the Feature Receiver to try to get the form to tie into the fields of the list item:
IListWebPart listWebpart = webpart as IListWebPart;
listWebpart.PageType = PAGETYPE.PAGE_EDITFORM;
listWebpart.ViewFlags = SPViewFlags.None;
Unfortunately, no joy. And that is as far as I got. Hopefully you'll have better luck.