HavenDV / H.Generators.Extensions

A set of extensions to simplify the code of generators
MIT License
11 stars 3 forks source link

Do not output ref assemblies #1

Closed espenrl closed 2 years ago

espenrl commented 2 years ago

There is a issue with NuGet packages which contains ref assemblies like Microsoft.CSharp and System.Runtime.Serialization.Primitives. Ref assemblies are only for compilation, and not for runtime execution. I've learned a lot about .NET Standard, NuGet and MSBuild during the last hours. :)

ResolvedCompileFileDefinitions points to these ref files, and my fix is as simple as replacing \ref\ with \lib\. Ref and lib should always come in pair, so it should be an okay solution to the problem.

I do not know if MSBuild ever will produce forward slashes. The code only handles backward slashes.

Fixes H.NSwag.Generator

I'm using H.NSwag.Generator which is a great tool. I can only build using full MSBuild. It fails using dotnet build because Microsoft.CSharp.dll can't be loaded. I've tested and verified that H.NSwag.Generator works using this fix for dotnet build.

HavenDV commented 2 years ago

Hello. Thanks a lot for this PR, I didn't know about ref directories in nuget package Can you quickly test if this will work? @(ResolvedCompileFileDefinitionsWithoutSystem->Replace('\ref\', '\lib\')->Replace('/ref/', '/lib/'))

espenrl commented 2 years ago

It works. I've added the change.

without fix

Added generation time reference: <redacted>\.nuget\packages\microsoft.csharp\4.7.0\ref\netstandard2.0\Microsoft.CSharp.dll

with fix

Added generation time reference: <redacted>\.nuget\packages\microsoft.csharp\4.7.0\lib\netstandard2.0\Microsoft.CSharp.dll
espenrl commented 2 years ago

Oh, btw. It's a bit confusing that the latest packages for H.NSwag.Generator are in the 13.15.x range, while the highest version is in the 13.16.x range. Dependabot always suggest me to update, and I never really know if there is a new 13.15.x release. It would have been awesome if this was sorted out.

image

HavenDV commented 2 years ago

It happened due to the fact that the latest version of NSwag had problems that were not solved for a long time: https://github.com/RicoSuter/NSwag/issues/4012 https://github.com/RicoSuter/NJsonSchema/pull/1522 I think this issue is already settled, at least 4 months to accept the PR, and I will release a new version already according to the latest version of NSwag after accepting this PR.

espenrl commented 2 years ago

I see, you're following the versioning of NSwag. Makes sense.