Azure 管道 NuGet 还原无法在 csproj 文件中设置 MsBuild 属性
Azure pipeline NuGet restore fails to set MsBuild properties in csproj files
我正在尝试为 C# 项目设置管道,该项目使用构建配置来决定安装哪个包。我可以在 Visual Studio 中构建得很好,但是在 Azure Pipelines 上使用 NuGetCommand@2 无法恢复包。看起来在使用该命令时,我在 csproj 文件中创建的 属性 未设置,因此 NuGet 会尝试查找包的无效版本。有什么解决办法吗?
csproj:
...
<PropertyGroup Condition="$(Configuration.Contains('2020'))">
<RevitVersion>2020</RevitVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autodesk.Revit.SDK" Version="$(RevitVersion).*" IncludeAssets="build; compile" />
</ItemGroup>
管道:
...
variables:
solution: '**/*.sln'
projects: '**/*.csproj'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release 2020'
steps:
- task: NuGetToolInstaller@1
displayName: 'Install NuGet'
inputs:
versionSpec:
- task: NuGetCommand@2
displayName: 'Restore packages'
inputs:
command: 'restore'
restoreSolution: '$(solution)'
configuration: $(buildConfiguration)
feedsToUse: 'select'
vstsFeed: '<private feed id>'
错误:
error MSB4018: System.ArgumentException: '.*' is not a valid version string.
It looks like when using that command, the property I created in the
csproj file doesn't get set, so NuGet tries to find an invalid version
of the package. Is there any way around this?
Local Nuget Restore command 不支持 Configuration
开关。
Online Nuget task 支持 Configuration
开关,但是只有 nuget pack
命令支持此开关。在线 Nuget 任务有四个命令:Restore,Pack,Push,Custom
,Configuration
输入 仅 对 nuget Pack
有效。这就是为什么 nuget pack 会忽略 configuration: $(buildConfiguration)
,即使您在编辑 yaml 管道时没有收到 warning/error。
该任务的配置输入仅适用于 nuget pack!
类似讨论请查看, , link3。
这是 Github/Nuget 的建议。您可以尝试使用 Nuget.config 文件和 PAT 为 msbuild /t:restore
.
提供身份验证
我正在尝试为 C# 项目设置管道,该项目使用构建配置来决定安装哪个包。我可以在 Visual Studio 中构建得很好,但是在 Azure Pipelines 上使用 NuGetCommand@2 无法恢复包。看起来在使用该命令时,我在 csproj 文件中创建的 属性 未设置,因此 NuGet 会尝试查找包的无效版本。有什么解决办法吗?
csproj:
...
<PropertyGroup Condition="$(Configuration.Contains('2020'))">
<RevitVersion>2020</RevitVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autodesk.Revit.SDK" Version="$(RevitVersion).*" IncludeAssets="build; compile" />
</ItemGroup>
管道:
...
variables:
solution: '**/*.sln'
projects: '**/*.csproj'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release 2020'
steps:
- task: NuGetToolInstaller@1
displayName: 'Install NuGet'
inputs:
versionSpec:
- task: NuGetCommand@2
displayName: 'Restore packages'
inputs:
command: 'restore'
restoreSolution: '$(solution)'
configuration: $(buildConfiguration)
feedsToUse: 'select'
vstsFeed: '<private feed id>'
错误:
error MSB4018: System.ArgumentException: '.*' is not a valid version string.
It looks like when using that command, the property I created in the csproj file doesn't get set, so NuGet tries to find an invalid version of the package. Is there any way around this?
Local Nuget Restore command 不支持 Configuration
开关。
Online Nuget task 支持 Configuration
开关,但是只有 nuget pack
命令支持此开关。在线 Nuget 任务有四个命令:Restore,Pack,Push,Custom
,Configuration
输入 仅 对 nuget Pack
有效。这就是为什么 nuget pack 会忽略 configuration: $(buildConfiguration)
,即使您在编辑 yaml 管道时没有收到 warning/error。
该任务的配置输入仅适用于 nuget pack!
类似讨论请查看
这是 Github/Nuget 的建议。您可以尝试使用 Nuget.config 文件和 PAT 为 msbuild /t:restore
.