我有一个看起来像这样的管道任务
- task: VSBuild@1
displayName: 'MSBuild $(solution)'
inputs:
solution: '$(mainProject)'
vsVersion: '17.0'
msbuildArgs: '/p:OutputPath=$(Build.ArtifactStagingDirectory) /p:DebugType=full'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
哪里
variables:
solution: '**/mySolution.sln'
mainProject: '**/web/myProject.csproj'
buildPlatform: 'Any CPU'
buildConfiguration: Azure
它会生成一个 MSBuild 命令,例如
"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\msbuild.exe" "D:\a\1\s\web\myProject.csproj"
/nologo
/nr:false
/dl:CentralLogger,"....MSBuild.Logger.dll";"RootDetailId=some-guid|SolutionDir=D:\a\1\s\web\|enableOrphanedProjectsLogs=true"*ForwardingLogger,"D:\a\_tasks\...MSBuild.Logger.dll"
/p:OutputPath=D:\a\1\a
/p:DebugType=full
/p:platform="Any CPU"
/p:configuration="Azure"
/p:VisualStudioVersion="17.0"
/p:_MSDeployUserAgent="..."
csproj 设置看起来像
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Azure|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE;Azure</DefineConstants>
<Optimize>true</Optimize>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
该常量永远不会进入最终版本。如果我将
/p:DefineConstants="TRACE;Azure"
添加到我的 [email protected]
中,那么一切都会很好。但为什么通过我的 csproj 定义的常量不受尊重?
项目的情况是:
Condition="'$(Configuration)|$(Platform)' == 'Azure|AnyCPU'"
$(Platform)
预计为 AnyCPU
(没有空格)。
管道变量是:
buildPlatform: 'Any CPU'
Any CPU
(带空格)。 Any CPU
和 AnyCPU
不匹配。由于您是直接构建项目,因此使用:
buildPlatform: 'AnyCPU'
有一个古老的“问题”,解决方案文件使用
Any CPU
(带空格),项目使用 AnyCPU
(不带空格)。构建解决方案文件后,Any CPU
解决方案平台将映射到项目的AnyCPU
。
Visual Studio UI 显示“任何 CPU”,我认为这是友好的,但不是正在传递的值。
当要构建的文件具有 .sln 文件扩展名时,请使用
Any CPU
;否则使用 AnyCPU
。您可以根据该逻辑调整您的 buildPlatform
变量。