-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Issue with generating SDK from .NET Core assembly. #1159
Comments
Try adding
to the ReferencePaths |
v11.14.0: We improved the assembly loader (mainly for .NET Core) so that it runs in a more isolated space and the loaded DLLs should better match the requested versions. Please test this with your projects to ensure that we didnt introduce regressions. Important if you have DLL loading problems:
For more information regarding assembly loading: https://github.com/RSuter/NSwag/wiki/Assembly-loading Main commit: 04576e4#diff-14dafe6661bab407ae5c0d7095ccd1f4 |
We found referencing the .nuget folder problematic as you cannot guarantee you'll pick up the correct version of the assembly. Try: <Copy SourceFiles="@(Reference)" DestinationFolder="$(OutDir)WebApi2SwaggerReferencePath" /> And point to The later cleanup with: <RemoveDir Directories="$(OutDir)WebApi2SwaggerReferencePath" /> Once we adopted this, life was bliss. |
Correct, in versions prior to v11.14 it was often the problem that the wrong DLL was loaded. In the latest version (v11.14) I try to find the best version based on the requested version: https://github.com/RSuter/NSwag/blob/master/src/NSwag.AssemblyLoader/AssemblyLoader.cs#L133 However, this also does not work very well because some DLLs/package versions are strangely missing from the cache (even if they are used) and also scanning the cache directory takes a lot of time... So using the nuget package cache directory is just a shortcut to test if assembly loading can work... |
I'd suggest recommending the above approach, it has been bullet proof for us, and you don't need to publish and build again, it's all done in one hit. |
What is @(Reference)? |
That is the resolved references from the .NET build target in MSBuild. By the way, this library has saved us many hours in our current project, so a massive thank you is due! |
You would put that in a target with |
I think it is not needed to add WebApi2SwaggerReferencePath to ReferencePaths as NSwag automatically searches in the directory where the specified assembly is located... |
But thanks, I'll try that... looks promising.. |
Is it also working with v11.14? |
In projects that use the new We researched this extensively and believe this is the optimal solution. |
Haven't testing in v11.14, but it should work as it puts all of the required assemblies in a folder and says "hey use these", and they are ones you want. |
If there was a version of |
Wow, this is really amazing!
|
Yeah, we have been using this for months (sorry for keeping it a secret), and it's lovely |
Credit to @shaynevanasperen who reduced our solution to that little nugget |
Yes, its much better than using "dotnet publish" with
|
Is there a way to make use of the Configuration variable in nswag.json? Currently I have the assemblyPaths as |
In the nswag.json set
and in nswag.json use the placeholder
in the .csproj task use
|
Did you mean a different file for I tried it anyway as |
Sorry, it's |
Ok yep, I had too early a version. It works fine when I upgraded to v11.14.1, but I get an different error for v11.15 (not sure if this has been reported elsewhere):
|
how are you executing nswag? via NSwag.MSBuild? do you also copy the references or publish first? |
Yes NSwag.MSBuild, same as your example above:
Not publishing first. |
Can you provide a sample project where i can reproduce this? |
Sure, see attached. The build fails unless I downgrade the NSwag packages to 11.14.1. |
Please retry with v11.15.1 |
Works great thank you! |
It works for us as we use the The assembly loading improvements are fantastic if running separately. |
So I've encountered a couple of issues here. (Possibly a new problem or at least recent) I can get my config to render if done through But after I added
And from then on could not load assemblies using To correct this, I removed the As @comdw commented, I also encountered the same error there ( If I remove |
@electricessence do you use the correct binary? |
@RSuter. When I was investigating this (still unresolved), I had the latest version from nuget. It was as if the DLL hint was wrong. But again, I did this a few times from a blown away repo. |
@RSuter & @slang25 - this was causing an issue in our project... we reference a dll that we have locally. So we have something like:
But now the Anyway, to cut a long story short, this fixed it:
Let me know if that's going to mess anything up... otherwise I suggest you update the documentation. |
@cvallance Nice find, looking at this again, I cannot find much info about I think it's worth updating the docs 👍 |
@slang25 looks good to me. Pleas update the docs if you have time... |
@cvallance Your suggestion really saved my day! Thank you! |
@cvallance So I read this thread months ago, but I didn't realize the subtle difference between these two
and - the one that works:
Interestingly for me the first would work OK with a |
If you want to start making sense of this sort of stuff, I recommend turning on binary logging and using MSBuildStructuredLog, you just add So here you'd run |
Hi Rico,
Could you please help.
When I try to generate SDK from .net core assembly project it rises an exception:
But the assembly exists.
The text was updated successfully, but these errors were encountered: