我喜欢创建一个包含.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 推送到提要后,nuget 会被其他项目消耗,这很有效。
消费项目解释s.props
和所有条件文件,并且PackageReference
s 也被添加。
当我使用 VS2019 构建项目时,一切正常。dotnet build
但是当我使用文件中的PackageReference
s构建时,.props
不会被添加。
我检查了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 工具作为其项目中的私有资产。