Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSwag.MSBuild 11.4.3.0 throwing error about assembly Microsoft.AspNetCore.Mvc.ViewFeatures #905

Closed
jim-strang opened this issue Aug 24, 2017 · 41 comments

Comments

@jim-strang
Copy link

Recently upgraded my .NET Core 1.1 app to 2.0, and also updated the NSwag packages I was using. Calling NSwag.MSBuild inside of a pre-build event:

$(NSwagExe) webapi2swagger /assembly:"$(SolutionDir)API\bin\$(Configuration)\netcoreapp2.0\API.dll" /output:API.swagger.json

Produces the following error:

4>  NSwag command line tool for .NET 4.6+, toolchain v11.4.3.0 (NJsonSchema v9.4.8.0) (x64)
4>  Visit http://NSwag.org for more information.
4>  NSwag bin directory: C:\Users\jstrang\.nuget\packages\nswag.msbuild\11.4.3\build
4>  System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.
4>  File name: 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'

Anyone else having this issue with .NET Core 2.0?

@RicoSuter
Copy link
Owner

RicoSuter commented Aug 24, 2017

Is the file "'Microsoft.AspNetCore.Mvc.ViewFeatures.dll" located in "$(SolutionDir)API\bin$(Configuration)"?

Its important to first "dotnet publish" so that all required dlls are available in the output dir...

@jim-strang
Copy link
Author

Nope, but that doesn't seem to matter (unless I am completely missing something here). Its the NSwag.exe inside of ".nuget\packages\nswag.msbuild\11.4.3\build" that is missing "Microsoft.AspNetCore.Mvc.ViewFeatures" as well as the Mvc.Core.dll

@jim-strang
Copy link
Author

And yes, definitely doing a dotnet publish on the API project before trying to call NSwag on the API assembly. The spot where it is failing is on $(NSwagExe) webapi2swagger , and the same result if I call NSwag.exe (the one in ".nuget\packages\nswag.msbuild\11.4.3\build") directly through command line. It was working as-is with .NET Core 1.1 and the most-recently-compatible version of NSwag.

Here's the gist of the build event:

dotnet publish "$(SolutionDir)API\API.csproj" --configuration "$(Configuration)"
$(NSwagExe) webapi2swagger /assembly:"$(SolutionDir)API\bin\$(Configuration)\netcoreapp2.0\API.dll" /output:API.swagger.json
$(NSwagExe) swagger2csclient /input:API.swagger.json /classname:{controller}Client /namespace:API.Client /output:Clients.Generated.cs
$(NSwagExe) swagger2tsclient /input:API.swagger.json /generateClientClasses:false /generateClientInterfaces:false /typeStyle:Interface /output:ServerModels.ts"

@RicoSuter
Copy link
Owner

The msbuild package still runs in full .net 4.6.2 and maybe this fw is not able to load .net core 2.0 assemblies? Maybe we need a .net 4.7 or a .net core 2.0 version? Only the npm package is currently published with a .net core 2.0 version ("--core 2.0" switch)

@RicoSuter
Copy link
Owner

Can you create a repro of the problem?

Btw: You should use a nswag.json file and just run "nswag.exe run nswag.json" - much simpler to manage the config.

@jim-strang
Copy link
Author

Sure, I'll create a sample project tonight or tomorrow and reply back here. Thank you for the tip about the json config, I'll definitely incorporate that. I'll keep you posted on the repro.

@jim-strang
Copy link
Author

jim-strang commented Aug 24, 2017

https://github.com/jim-strang/nswag-issue905-sample

Here's an example solution. Try building the API.Client project in Release mode and you will see the build errors. I tried to make it as simple as possible.

Please let me know if there is anything else I can do to help out with this issue!

@RicoSuter
Copy link
Owner

Strange, why are the ASP.NET Core assemblies not in the publish folder? Where are they loaded from?

Btw: NSwag also provides a middleware like Swashbuckle and Swagger UI, you don't need both :-) - and if the Swagger is generated in-process, you avoid all these problems - but you cant generate code during compilation... (ie the server must be running and serve the spec for the code generator)

@jim-strang
Copy link
Author

Right yeah - that makes sense, removing the Swashbuckle swagger gen is on my todo list. I want to have it done during the build so we can do c# and TS code gen based on the spec.

I assume that the .NET Core assemblies are pulled from the dotnet SDK location? Maybe dotnet publish changed between 1.1 and 2.0 and there's some other flag needed to copy ALL assemblies to publish. I'll look into that.

@RicoSuter
Copy link
Owner

RicoSuter commented Aug 24, 2017

Ok, I've got one step further. If I add

<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>

to the .csproj, all required dlls are published. Now the assembly "netstandard" cannot be loaded...

To avoid publishing all these DLLs, we have to find where these are installed on the PC and add this path to the ReferencePaths setting

Ref: https://github.com/dotnet/cli/issues/6516

@RicoSuter
Copy link
Owner

If I upgrade NSwagStudio to .NET 4.6.1 and install NETStandard.Library.NETFramework it works

https://www.nuget.org/packages/NETStandard.Library.NETFramework/2.0.0-preview2-25405-01

image

But NETStandard.Library.NETFramework is deprecated :)

@jim-strang
Copy link
Author

Nice! Good find. How about the regular NETStandard.Library?

https://www.nuget.org/packages/NETStandard.Library/

@RicoSuter
Copy link
Owner

Nope, doesn't work... only working with the prerelease version of NETStandard.Library.NETFramework...

There must be something missing...

@RicoSuter
Copy link
Owner

Ref: dotnet/sdk#1220

Maybe NSwagStudio.csproj is using the old MSBuild tooling and this is why it is not working?

@RicoSuter
Copy link
Owner

If i run the .net core 2.0 nswag cmd line tool it also works (if the dlls are in the publish folder).

@RicoSuter
Copy link
Owner

Ill do some more tests tomorrow, already too late..

@jim-strang
Copy link
Author

No worries, let me know if I can help out in any way

@RicoSuter
Copy link
Owner

Ok, I think I've found a solution. If you add

<DependsOnNETStandard>true</DependsOnNETStandard>

to your project (NSwagStudio, NSwag.Console), the loading works if the web app is published with

<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>

I've updated the wiki, but we should improve it...

https://github.com/RSuter/NSwag/wiki/WebApiAssemblyToSwaggerGenerator#net-core

@jim-strang
Copy link
Author

jim-strang commented Aug 25, 2017

I'm looking into ways to have something "pick up" the .net core assemblies without having to publish with <PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>. Maybe something to do with dotnet store?

Unless they should all be included with NSwag itself? Not sure

@RicoSuter
Copy link
Owner

Including with nswag is not an option because we would have to pick a specific version of asp.net - but nswag supports all versions of asp.net. This would force the users to always use the same asp.net version as nswag.

@RicoSuter
Copy link
Owner

Maybe this option can be set as dotnet publish cmd line param?

Or you have to find the cache location and add this path to the ReferencePaths setting.

@RicoSuter
Copy link
Owner

@jim-strang
Copy link
Author

jim-strang commented Aug 25, 2017

dotnet publish with --self-contained seems to do exactly that (after you also specify a --runtime value)

Or maybe includes every assembly inside the Microsoft.AspNetCore.All metapackage? :)

@josemotta
Copy link

Hi,
I arrived here due original error at top, then I cloned Jim´s repo and added paths below to NSwag Studio in order to search for missing assemblies:

C:_git\nswag-issue905-sample\API\bin\Release\PublishOutput
C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.0

Now error changed to a 4.6.1 version of another assembly:

Could not load type 'System.Object' from assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' because the parent does not exist.

I hope we can fix issue in order to run netcore 2 with swagger automation

@RicoSuter
Copy link
Owner

For me the latest code in master works ehen publishing all dlls... only problem is that the appveyor ci builds are no longer working.

@RicoSuter
Copy link
Owner

OK, now the CI build looks good... should we release so that you can really test this?

@jim-strang
Copy link
Author

Works with me, if you push out a new release I can test it on my end later today and report back

@jim-strang
Copy link
Author

NSwag.MSBuild 11.5.0 is looking good for me!

@josemotta
Copy link

It seems .msi is broken, I will wait for Rico fix.

@RicoSuter
Copy link
Owner

Fixed.

@RicoSuter
Copy link
Owner

Please report any problems. And we should update the wiki with tips how to load core assemblies:

https://github.com/RSuter/NSwag/wiki/WebApiAssemblyToSwaggerGenerator#net-core

Maybe we should create a new page for the dll loader alone.

@josemotta
Copy link

Hi, good news! I noticed that .msi is missing from the newest NSwag Build 868. I was testing at Windows and already uninstalled the previous version. Should I use now the command line? In this case, I need to double check documentation in order to start using .zip file.

@RicoSuter
Copy link
Owner

The latest MSI should be fine...

@RicoSuter RicoSuter reopened this Aug 30, 2017
@josemotta
Copy link

Sorry, I am missing something. The .msi from NSwag v11.5.0 (Build 866) is broken. Should I replace the .exe/.dll files in the Program Files folder with newest from NSwag Build 868 .zip?

@RicoSuter
Copy link
Owner

Its fixed in v11.5.1, use this:

https://github.com/RSuter/NSwag/releases/tag/NSwag-Build-868

@josemotta
Copy link

Sorry again, there is no .msi installer there, only .zip and source code.

@RicoSuter
Copy link
Owner

Sorry, use this:

http://rsuter.com/Projects/NSwagStudio/installer.php

Will add tomorrow

@josemotta
Copy link

Great! Got it, error free now, 11.5.1 passed over the last error. I will keep testing.

@josemotta
Copy link

Working fine! Thank you.

@RicoSuter
Copy link
Owner

Created a new wiki page:

https://github.com/RSuter/NSwag/wiki/Assembly-loading

please update with your tips, findings, etc...

@jim-strang
Copy link
Author

updated with a link to the runtime catalog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants