我有以下代码:
#if PC
var rootPath = Path.Combine("dist");
#else
var rootPath = Path.Combine(@"/bin/bash");
#endif
我想在发布程序时编写不同的批处理文件来决定是否添加宏“PC”。
但是我在dotnetpublish命令下没有找到答案。
在 .csproj 文件中添加配置 (Pc),然后添加
PC
符号:
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Pc|AnyCPU'">
<DefineConstants>$(DefineConstants);PC</DefineConstants>
</PropertyGroup>
使用
-c
选项选择此配置:
dotnet publish -c:Pc
使用 msbuild 的
-getProperty
和 -p
选项来定义符号:
SET cmdGetProp='dotnet msbuild -getProperty:DefineConstants'
FOR /F "tokens=*" %%s IN (%cmdGetProp%) DO SET prop=%%s
dotnet publish -p:DefineConstants=\"%prop%;PC\"