我想创建一个包含 .props
文件的 NuGet 包。
.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>
在将nuget打包并推送到feed后,该nuget会被其他项目使用,这些项目可以正常工作。
消费项目会解释.props
和全部条件文件,并添加PackageReference
s。
当我使用VS2019构建项目时,一切正常。但是当我使用dotnet build
构建时,来自.props
文件的PackageReference
s不会被添加。
我检查了project.assets.json
,它们是不同的。VS2019将工具添加到资产文件:
...
"CycloneDX/0.9.0": {
"type": "package"
},
"dotnet-sonarscanner/4.7.1": {
"type": "package"
},
"GitVersion.Tool/5.1.1": {
"type": "package"
},
...
但dotnet build没有将其添加。
是否需要在dotnet restore命令中添加属性或标志?或者您有任何关于不同行为的想法。
我的目标是,使用这些项目的其他项目将dotnet工具作为私有资源包含在其项目中。