HavenDV / H.Generators.Extensions

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

Project references support #15

Open valchetski opened 1 day ago

valchetski commented 1 day ago

I've tried to use your library as suggested in RicoSuter/NJsonSchema#1726. At first, amazing library đŸ™‚. It works like a charm for transient NuGet packages. However, I have one question and one issue with project references

Question

Does it support the automatic inclusion of referenced projects (also transient references) DLLs into the NuGet package?
For example, is it possible to avoid these lines and have these DLLs included automatically?

<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
<None Include="$(OutputPath)\NJsonSchema.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
<None Include="$(OutputPath)\NJsonSchema.Annotations.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
<None Include="$(OutputPath)\NJsonSchema.CodeGeneration.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
<None Include="$(OutputPath)\NJsonSchema.CodeGeneration.CSharp.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />

And avoid these for the case when Source Generator is used as project reference itself:

<PropertyGroup>
  <GetTargetPathDependsOn>
      $(GetTargetPathDependsOn);GetDependencyTargetPaths
  </GetTargetPathDependsOn>
</PropertyGroup>

<Target Name="GetDependencyTargetPaths">
  <ItemGroup>
      <TargetPathWithTargetPlatformMoniker Include="$(OutputPath)\NJsonSchema.dll" IncludeRuntimeDependency="false" />
      <TargetPathWithTargetPlatformMoniker Include="$(OutputPath)\NJsonSchema.Annotations.dll" IncludeRuntimeDependency="false" />
      <TargetPathWithTargetPlatformMoniker Include="$(OutputPath)\NJsonSchema.CodeGeneration.dll" IncludeRuntimeDependency="false" />
      <TargetPathWithTargetPlatformMoniker Include="$(OutputPath)\NJsonSchema.CodeGeneration.CSharp.dll" IncludeRuntimeDependency="false" />
  </ItemGroup>
</Target>

Issue

It appears that it somehow treats all project references as dependent NuGet packages.

Try to generate a NuGet package for the NJsonSchema.SourceGenerators.CSharp project from https://github.com/valchetski/NJsonSchema/tree/source-generator-h-generators Then try to install it and see that it gonna install all the packages. image

This is something I would like to disable. Or at least have it configurable.

If you do the same from https://github.com/valchetski/NJsonSchema/tree/source-generator branch (H.Generators.Extensions library is not installed there) then it'll install the bare minimum which is what I need: image Thanks in advance!

HavenDV commented 1 day ago

https://github.com/HavenDV/H.Generators.Extensions/blob/main/src/libs/H.Generators.Extensions/build/H.Generators.Extensions.props All the magic happens here. I'm not sure if you don't intersect with this file, I would try to remove GetDependencyTargetPaths/GetTargetPathDependsOn in your code and try to trust it completely. But I haven't tried testing this configuration when there is a non private package like Newtonsoft.Json here

I also tried releasing a new version of H.NSwag.Generator and it seems to still work correctly -

image

I also don't see any extra dependencies in the .nuspec file

HavenDV commented 1 day ago

The main problem with dependency code via PKG is transitive dependency version hell, because packages almost always use a non-latest version