Rider: How to generate a OpenApi (Swagger) web service reference? - swagger

With Unchase.OpenApi exists a Visual Studio Extension to generate code for web services with NSwag.
This leads me to the following question: Is there a way to create a web service reference based on a swagger.json reference in Rider?

I haven't used the extension. Based on the gif I conclude, it generates clients one time and then the generated code is commited.
We use in our project another approach.
Add an OpenAPI reference to the csproj file
<OpenApiReference Include="..\relative\path\to\openapi.json" CodeGenerator="NSwagCSharp" ClassName="{controller}Client" Link="OpenAPIs\openapi.json" />
Reference the package NSwag.ApiDescription.Client
The client(s) will be generated before building the project and placed in obj directory. Since that they are available to use in your code.

Related

Custom Build Action similar to AndroidResource

I am trying to organise an Android project's layout files. Having already worked with MVC, I tried to apply that architectural pattern to the Android project.
Suppose I have a folder structure in my Android project:
Areas > SomeAreaName > Views > details_layout.xml
Setting the Build Action on "details_layout.xml" to AndroidResource results in an "invalid file path" error which is understandable as Android does not allow for files in different locations other than the predefined "res" folder and subfolders.
Is it possible to create a custom Build Action (e.g. AndroidResourceMvc) that can utilise the existing AndroidResource Build Action and with the added ability to appropriately map layout files? If so, how would I go about this?
I've looked at the AndroidResource file and with it being internal and private I don't really have access to it. Neither am I able to just use the raw source code as it imports some namespaces that I also do not have access to (or I just can't seem to find them if they're publicly available).
I'm using Visual Studio 2019 and a Xamarin Android C# project.

A way to use unity.configuration in azure functions V2 - .net core

I have requirement to resolve dependencies from xml file and have used unity dependency injection.
Everythins is working fine in console and ASP.net core applications.
However in .net core functions below piece of code is returning null.
var unitySection = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
I have added app.config and unity.config and marked the properties to be copied to bin on build.
Default output type Function app is Class library, changed to console as well but no luck.
Any help is appreciated.
From v2, azure function doesn't support ConfigurationManager and you can refer to environment variables, you need to use System.Environment.GetEnvironmentVariable.
Please have a look of this reply of azure teams:
https://github.com/Azure/azure-functions-core-tools/issues/328#issuecomment-355697529
ConfigurationManager is only be used in azure function v1. From v2, it has been moved to a new configuration model:
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?tabs=basicconfiguration&view=aspnetcore-3.1
And not based on ConfigurationManager or its APIs any more.:)

CSV Type provider

I am trying to find a easy example or introduction to a CSV Type provider. So I followed this link to help me get started. Now I have a Visual Studio 2012 students edition and while documentation says that F# 3.0 has the CSV type provider I am not able to find it. So I am trying to use a type provider for a local CSV File. What I see is that the CSV TypeProvider mentioned does not exist at all. Since the given examples don't really compile I looked around and used something like this to load the oData services :
#r "FSharp.Data.TypeProviders"
///loading a stackoverflow odata type provider
type stackOverflow = Microsoft.FSharp.Data.TypeProviders.ODataService<"http://data.stackexchange.com/stackoverflow/atom">
So this is a bit different from what is mentioned in the example page above. I am not able to see the csv type provider. I use the Visual Studio IDE to list the type providers and csv is not listed. I tried updating the packages using nuget and this still persists. Can anyone point the right documentation on how to work with a csv type provider and also the right updated links where a simple example could be found?
FSharp.Data isn't a built-in library, so you either need to use nuget or manually download the package. See here for more information on where to get it (and how to use it).
If you manually download the project you can put it wherever you want and then simply use a file path to reference it with #r. For a path relative to your project, use the __SOURCE_DIRECTORY__ symbol, otherwise you can simply use the absolute file path of the .dll.
After referencing the dll, you still need to open the namespace, so you need to have open FSharp.Data after you reference the dll.
Alright so this is what I did. I used Nuget to manage references and I installed the FSharp.Data and FSharp.Data.TypeProviders and like #mydogisbox mentioned I then use the open FSharp.Data to load the csv files i.e.
open FSharp.Data.Csv
While this works if I use Nuget, it doesn't work otherwise. So have to figure out how to do that. For now this should suffice I guess.

Adding a service reference in ASP.NET MVC 4

I have two projects: Mvc3TestSvcRef & Mvc4TestSvcRef.
Mvc3TestSvcRef is from the ASP.NET MVC 3 template for an intranet application.
Mvc4TestSvcRef is from the ASP.NET MVC 4 template for an intranet application.
I'm trying to add a service reference.
In Mvc3TestSvcRef, I right-click the project (or the References folder) and choose Add Service Reference. I point to the URL, click Go. When the reference is resolved, I enter a namespace and click OK. As expected, I see the section added to config with the bindings and client tags completed.
I can import: "using Mvc3TestSvcRef.MySvcRef;"
And write code like:
using (var cl = new MyServiceClient())
{
cl.DoStuff();
}
In Mvc4TestSvcRef, I follow the same steps, but there is no system.servicemodel added to config. Additionally the import: "using Mvc4TestSvcRef.MySvcRef;" cannot be resolved.
I've tried this for MVC 4 from both Visual Studio 2010 and Visual Studio 2012.
Was there a major change to the process for adding service references in ASP.NET MVC 4 project type, or am I missing something or have corrupt install?
There was no code in Reference.cs, just comments:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.17929
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
I copied the reference.cs from the project that worked and modified the namespace, then added the section from the working project into the MVC 4 project and was still having an issue.
I tried to build and I got several warnings and an error. Failed to generate code for the service reference 'MySvcRef'. Please check other error and warning messages for details.
That led me to this article: Service Reference Error: Failed to generate code for the service reference
So I unchecked the Reuse types in all referenced assemblies from the Advanced section.
This seems to have generated a good service reference. Although, I should point out that if you have something in say System, like System.TimeSpan for example, that is used as a DataMember in one of your DataContracts, the reference will now have TimeSpan in the reference namespace, not from it's origin. So, the client would see any System.Timespan properties as ReferenceNameSpace.Timespan, which may throw off comparisons and such. The better answer here is to include specific assemblies from the reference and don't check the box for System.Web.Http, as pointed out in the comments below
I don't know if it is too late, but here is the solution "When you add the reference, on advanced setting remove the reuse types checkbox."

How to create simple Wix setup project

We have a client/server application which includes a Windows Service and a Winform client tool. I've managed to create a Wix project in Visual Studio (2010, using the wix 3.5 toolset). I'm using the "harvest" feature on the references instead of specifying every file, because there are many library projects involved.
Problems I'm trying to figure out:
How to include referenced DLLs? Some are in the GAC, some are in a relative path within the workspace. I assume I could list each file explicitly but it seems like there should be a way for Wix to autodetect them.
How to install the service while "harvest" is enabled. All the examples I've seen require adding an explicit element with KeyPath=true. However this doesn't work with the harvest=true setting.
I realize that the harvest functionality might be a convenience which is not feasible when there are more complex things going on. Should I give up on harvesting and just try to specify each file explicitly?
Most of the examples I've seen on Wix have been just snippets of xml files. Is there anywhere I can find complete real-world examples of installing services other non-trivial setup features?
Use WixEdit. http://wixedit.sourceforge.net/
It's very easy to import an entire folder using it.
Also, check out the great WiX tutorial here: http://www.tramontana.co.hu/wix/
5.4 Services Rendered
Services can be installed and started automatically.
http://wix.tramontana.co.hu/tutorial/net-and-net/services-rendered
For even more information, check out more WiX documentation here: http://wixtoolset.org/documentation/manual

Resources