简体   繁体   English

如何在C#项目中以编程方式(例如在预生成事件中)以编程方式设置Visual Studio 2015的OutDir属性?

[英]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.

相关问题 如何以编程方式将AssemblyInfo.cs更新为预生成事件(Visual Studio / msbuild) - How to programatically update AssemblyInfo.cs as a Pre-Build event (Visual Studio / msbuild) Visual Studio C#不会生成因预生成事件而更改的文件 - visual studio c# does not build files that were change by pre-build event 在每次构建时在 Visual Studio C# 中运行预构建事件,而不总是触发目标重建 - Run pre-build event in Visual Studio C# on every build without always triggering target rebuild 将 C# 文件作为预构建事件运行 Visual Studio (.NET Core) - Run a C# file as a pre-build event Visual Studio (.NET Core) 如何使用Visual Studio 2013预构建事件从构建中排除脚本? - How do i use Visual Studio 2013 Pre-Build event to exclude a script from build? 如果出现问题(VS 2010 / C#),我怎么能有一个预构建事件停止构建? - How can I have a pre-build event halt the build if something went wrong with it (VS 2010/C#)? 有没有办法从C#中的代码中修改Visual Studio 2008或2010项目预构建事件? - Is there a way to modify Visual Studio 2008 or 2010 project pre-build events from within your code in C#? 如何从C#项目的构建事件中访问Visual Studio解决方案级平台? - How can you access the Visual Studio solution level platform from a C# project's build event? 在 Visual Studio 的预构建中使用 webpack - Using webpack in Visual Studio's pre-build 在Visual Studio 2010中预构建 - Pre-build in Visual Studio 2010
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM