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

PackageReference defined in .props file not appearing in project.assets.json when using dotnet restore #9132

Closed
cmenzi opened this issue Feb 3, 2020 · 1 comment
Labels
Functionality:Restore Resolution:ByDesign This issue appears to be ByDesign Resolution:Duplicate This issue appears to be a Duplicate of another issue Style:PackageReference

Comments

@cmenzi
Copy link

cmenzi commented Feb 3, 2020

I have a tools.props file which contains some PackageReference's. When I import the file into a .csproj either via <Import Project="tools.props" /> or via a NuGet package where to 'tools.propsfile in packed into thebuildfolder, then all dependencies defined in the.propsare not appearing inproject.assets.json`.

The funny thing is, that when using VS 2019 and build it, then everything works and project.assets.json created correctly.

But when using dotnet restore command or msbuild /t:restore the dependency are not it project.assets.json.

tools.props

<Project>
  <ItemGroup>
    <PackageReference Include="trx2junit" Version="[1.3.0]" PrivateAssets="All" ExcludeAssets="All" />
    <PackageReference Include="GitVersion.Tool" Version="[5.1.1]" PrivateAssets="All" ExcludeAssets="All" />
    <PackageReference Include="dotnet-sonarscanner" Version="[4.7.1]" PrivateAssets="All" ExcludeAssets="All" />
    <PackageReference Include="ReportGenerator" Version="[4.4.6]" PrivateAssets="All" ExcludeAssets="All" />
    <PackageReference Include="NuGet.CommandLine" Version="[5.4.0]" PrivateAssets="All" ExcludeAssets="All" />
    <PackageReference Include="CycloneDX" Version="[0.9.0]" PrivateAssets="All" ExcludeAssets="All" />
  </ItemGroup>
</Project>

When I define the ItemGroup directly in the .csproj and not in the .props file, then it works aswell.

Why is the behavoir differnent in VS than in msbuild or dotnet restore?

Is there a hint, flag, property to pass, they dotnet restore should handle those package references same as they would be directly defined in the csproj?

@cmenzi cmenzi changed the title PackageReference defined in .props file ot appearing in project.assets.json when using dotnet restore PackageReference defined in .props file not appearing in project.assets.json when using dotnet restore Feb 3, 2020
@nkolev92
Copy link
Member

nkolev92 commented Feb 4, 2020

This is by design.

NuGet explicitly excludes those targets from affecting restore.
If a package contains a build/package.targets file that contains a PackageReference the output of restore will change based on if the project had previously been restored.

See #3604.

Doc issue to clarify this: https://github.com/NuGet/docs.microsoft.com-nuget/issues/1872

The Visual Studio experience is different due to a project-system bug, see: dotnet/project-system#3734

If your package has dependencies, it should declare them as such.
Otherwise you might need to consider an msbuild sdk, like https://github.com/microsoft/MSBuildSdks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Functionality:Restore Resolution:ByDesign This issue appears to be ByDesign Resolution:Duplicate This issue appears to be a Duplicate of another issue Style:PackageReference
Projects
None yet
Development

No branches or pull requests

2 participants