Reputation: 4311
Scenario 1 (Good):
Newtonsoft.Json
).nupckg
file (by NuGet package Explorer of just by 7-Zip) - you'll find, .nuspec
contains section:<dependencies>
<group targetFramework=".NETStandard2.0">
<dependency id="Newtonsoft.Json" version="13.0.1" exclude="Build,Analyzers" />
</group>
</dependencies>
So, if you install this .nupckg
to some project, Newtonsoft.Json
will be installed also. Good!
BUT! lets see Scenaro 2 (Bad):
Lets move the similar way:
.Package
project, you'll see, it's the same as our 1st example - it's Class-library with target framework .Net Standard 2.0)Newtonsoft.Json
).Package
, Properties -> Package -> You'll see, "Generate NuGet package on build" is already marked..nupckg
file (it is at .Package
project bin/Debug folder) - you'll find, .nuspec
DOES NOT contain section <dependencies>
.
So, when you install this .nupckg
to some project, Newtonsoft.Json
will NOT be installed to it.My questions:
.nuspec
of a Roslyn analyzer package?PS: I've found a solution, but I don't like it, `cos it depreciating the sense of packages management ('cos we just burn dependency dlls into our package). Is this the best solution?
Upvotes: 0
Views: 621
Reputation: 6218
The issue is that you have added
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
under xxx.Package project.
It will prevent all project references and nuget refeferences being packed into nupkg
(as nuget dependencies) when you pack the Analyzer.Package project. And the new Newtonsoft.Json
nuget package is also be prevented.
In other words, the node will prevent all referenced projects, installed nuget packages. And that is designed by the author. The goal of it from the author is to prevent the project references as nuget dependencies for nupkg. Otherwrise, it will turn out an error.
To fix it, it is easy. Just modify Analyzer.Package.csproj
file:
1) change the switch to false
.
<SuppressDependenciesWhenPacking>false</SuppressDependenciesWhenPacking>
2)And then selectively block the project references to be packaged. Use <PrivateAssets>All</PrivateAssets>
under that.
<ItemGroup>
<ProjectReference Include="..\Analyzer2.CodeFixes\Analyzer2.CodeFixes.csproj">
<PrivateAssets>All</PrivateAssets>
</ProjectReference>
<ProjectReference Include="..\Analyzer2\Analyzer2.csproj">
<PrivateAssets>All</PrivateAssets>
</ProjectReference>
</ItemGroup>
3) rebuild your project and then you will see the right behavior.
Upvotes: 2