[英]How can I set Visual Studio 2015's OutDir property programatically, e.g. in a pre-build event, in a C# project?
I need to set the "Output Path" field (which becomes $(OutDir)) of a VS 2015 C# project to a path that is elsewhere defined in an environment variable XX_OUT_DIR. 我需要将VS 2015 C#项目的“输出路径”字段(变为$(OutDir))设置为环境变量XX_OUT_DIR中其他位置定义的路径。
Setting the value of the textbox in the project properties build page to %XX_OUT_DIR%, or any permutation thereof, eg "%XX_OUT_DIR%", doesn't work - it just creates an "%XX_OUT_DIR%" directory when building, ie treating it as a string rather than resolving it to the text contained in the environment variable. 将项目属性构建页面中的文本框的值设置为%XX_OUT_DIR%,或其任何置换(例如“%XX_OUT_DIR%”)均不起作用-它仅在构建时创建一个“%XX_OUT_DIR%”目录,即对其进行处理作为字符串,而不是将其解析为环境变量中包含的文本。
I know in pre-build events, these environment variables are correctly resolved to their value. 我知道在构建前事件中,这些环境变量已正确解析为其值。
But, I cannot find a way to SET the value of OutDir as a pre-build event. 但是,我找不到一种将OutDir的值设置为预构建事件的方法。 I can only read it, which doesn't help me... 我只能阅读它,对我没有帮助...
Any ideas? 有任何想法吗?
Thank you! 谢谢!
You can change the value of $(OutDir) either from within by editing the csproj
file and changing the value. 您可以通过编辑csproj
文件并更改值从内部更改$(OutDir)的值。 You can create a special build configuration and use the Condition
attribute to handle your special circumstances. 您可以创建特殊的构建配置,并使用Condition
属性处理您的特殊情况。 The rest of the setting could remain the same. 其余设置可以保持不变。
<OutDir Condition=" '$(Configuration)' == 'Special' ">C:\MyDir</OutDir>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.