MSBuild - 使用配置 属性 覆盖配置 属性

MSBuild - Override configuration property by using configuration property

我在 Internet 上发现可以在构建期间使用 msbuild.exe -property=<PropertyName>=<value> 覆盖 属性。例如,我可以使用 msbuild.exe -property=OutDir=bin\ABC 来更改输出目录。

现在我的问题是,是否可以在覆盖语句中使用其他配置属性。意思是我想实现这样的目标:msbuild.exe -property=OutDir=$(SolutionDir)Output$(AssemblyName)$(AssemblyVersion)

没有。你不能这样做。 msbuild 命令行分配属性方法无法解析 MSBuild 如何获取值 --$(XXX)。那就是那个设计的。

如果这样做,您将在当前 cd 文件夹下得到名为 $(SolutionDir)Output$(AssemblyName)$(AssemblyVersion) 的输出文件夹。

因此您应该只在 msbuild 命令行下使用 outdir 的直接完整路径。

如果你仍然得到你想要的,你应该放弃 msbuild 命令行分配属性的方法,而是直接在 xxx.csproj 文件下添加它。

<PropertyGroup>

<OutDir>$(SolutionDir)Output$(AssemblyName)$(AssemblyVersion)</Outdir>

</PropertyGroup>

直接使用msbuild xxx\xxx.csproj -t:build构建项目。