简体   繁体   中英

props and targets with PackageReference in nuget package

I like to create a NuGet package with a .props file in it.

The .props file has following content:

<Project>
  <ItemGroup>
    <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" />
    <PackageReference Include="trx2junit" Version="[1.3.0]" PrivateAssets="All" ExcludeAssets="All" />
  </ItemGroup>

  <ItemGroup>
    <NukeSpecificationFiles Include="**\*.json" Exclude="bin\**;obj\**" />
    <NukeExternalFiles Include="**\*.*.ext" Exclude="bin\**;obj\**" />
    <None Remove="*.csproj.DotSettings;*.ref.*.txt" />

    <!-- Common build related files -->
    <None Include="..\build.ps1" />
    <None Include="..\build.sh" />

    <None Include="..\.nuke" LinkBase="config" />
    <None Include="..\global.json" LinkBase="config" Condition="Exists('..\global.json')" />
    <None Include="..\nuget.config" LinkBase="config" Condition="Exists('..\nuget.config')" />
    <None Include="..\GitVersion.yml" LinkBase="config" Condition="Exists('..\GitVersion.yml')" />
    <None Include="..\CODEOWNERS" LinkBase="config" Condition="Exists('..\CODEOWNERS')" />

    <None Include="..\.teamcity\settings.kts" LinkBase="ci" Condition="Exists('..\.teamcity\settings.kts')" />
    <None Include="..\.github\workflows\*.yml" LinkBase="ci" />
    <None Include="..\azure-pipelines.yml" LinkBase="ci" Condition="Exists('..\azure-pipelines.yml')" />
    <None Include="..\Jenkinsfile" LinkBase="ci" Condition="Exists('..\Jenkinsfile')" />
    <None Include="..\appveyor.yml" LinkBase="ci" Condition="Exists('..\appveyor.yml')" />
    <None Include="..\.gitlab-ci.yml" LinkBase="ci" Condition="Exists('..\.gitlab-ci.yml')" />
    <None Include="..\.travis.yml" LinkBase="ci" Condition="Exists('..\.travis.yml')" />
  </ItemGroup>
</Project>

After packing and pushing the nuget to the feed, the nuget gets consumed by other projects, which works.

The consuming project interprets the .props and also all conditional files and also the PackageReference s gets added.

When I build to project with VS2019 then all works fine. But when I build with dotnet build the PackageReference s from .props file don't get added.

I checked the project.assets.json and they are different. The VS2019 adds the tools to the asset file:

...
"CycloneDX/0.9.0": {
  "type": "package"
},
"dotnet-sonarscanner/4.7.1": {
  "type": "package"
},
"GitVersion.Tool/5.1.1": {
  "type": "package"
},
...

but dotnet build doesn't add it.

Is there a property or flag I need to add to the dotnet restore command? Or do you have an idea why the behavoir is different.

My goals is that the consuming projects have the dotnet tools as private assets in their projects.

No there is not a flag. You need to use dotnet pack instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM