.net - nuget 包中带有 PackageReference 的道具和目标
问题描述
我喜欢创建一个包含.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 工具作为其项目中的私有资产。
解决方案
不,没有旗帜。您需要改用 dotnet pack。
推荐阅读
- r - 未选择的条目显示在轴上 - Crosstalk+Plotly 条形图
- python - 如何弃用回调参数?
- javascript - 在 Array.map() 中调用 onClick (to setAttribute) 会引发错误 TypeError: Cannot read property 'toLowerCase' of undefined
- asp.net-mvc - RouteData 仅在 .NET Core 3 上不适用于 HttpContext
- java - 使用 Java 将 PySpark 提交到 Yarn 集群
- android - 如果 JSONArray 中的 id 相同,如何在一个 textview 上显示值
- android - Flutter 中的卡片轮播
- symfony - Symfony Query Builder:避免转义双引号
- firebase - 我在 Firestore 中有数据,并提交了值,但其中一些显示为 null
- java - 无法生成 DataBindingClass(Impl 确实生成)