简体   繁体   English

nuget 包中带有 PackageReference 的道具和目标

[英]props and targets with PackageReference in nuget package

I like to create a NuGet package with a .props file in it.我喜欢创建一个带有.props文件的 NuGet 包。

The .props file has following content: .props文件包含以下内容:

<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.在打包并将 nuget 推送到提要后,nuget 会被其他项目消耗,这是有效的。

The consuming project interprets the .props and also all conditional files and also the PackageReference s gets added.消费项目解释.props和所有条件文件,并PackageReference s。

When I build to project with VS2019 then all works fine.当我使用 VS2019 构建项目时,一切正常。 But when I build with dotnet build the PackageReference s from .props file don't get added.但是,当我使用dotnet build ,不会添加.props文件中的PackageReference s。

I checked the project.assets.json and they are different.我检查了project.assets.json ,它们是不同的。 The VS2019 adds the tools to the asset file: VS2019 将工具添加到资产文件中:

...
"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.但 dotnet build 没有添加它。

Is there a property or flag I need to add to the dotnet restore command?是否需要向 dotnet restore 命令添加属性或标志? 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.我的目标是消费项目将 dotnet 工具作为其项目中的私有资产。

No there is not a flag.不,没有旗帜。 You need to use dotnet pack instead.您需要改用 dotnet pack。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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