Is there a way to make user specific pre/post build events in Visual Studio projects?

无人久伴 提交于 2019-12-07 03:04:16

问题


I'm currently using a post build event in my project to copy my assemblies to another directory for debugging purposes. This is local to my machine, and is for debugging purposes only, so I would prefer to have it in a *.csproj.user file instead of a *.csproj file. I tried copying the responsible elements from the *.csproj to the *.csproj.user, but that didn't work.

Edit To clarify, I do not want to put user specific commands in the post-build event in the *.csproj file. Instead, I want to put the post-build event commands in the *.csproj.user file. (From the answers so far, this is looking impossible)

To give more context, it is not a project reference. I am copying my assembly to the directory of the application that loads the assemblies at runtime. (Think plugins)


回答1:


The short answer is no, not the way you want to do it :|

The slightly longer answer is sorta. You can in theory have specific build events triggered for individual users, but these would still be in the csproj file. You can run external events on builds and then allow these external events to run depending on what user is running them (as a script).

If this is for debug only I'd just insert them, do your build stuff and pull them out before uploading it to your version control system.




回答2:


Use an if statement and an enviroment variable (in double quotes if required)

if "$(Username)" == "MyUser"
  copy /y $(ProjectDir)memcached.$(ConfigurationName).config $(ProjectDir)memcached.config



回答3:


You can utilize a custom build target that has a condition triggered by an environment variable. Then only set that variable on your machine.




回答4:


Pre-/Post-build events are kept in the project file. VS provides no options.

You can introduce a custom (external) tool to perform such copying though and call it from menu, or macros and call it too.



来源:https://stackoverflow.com/questions/11690574/is-there-a-way-to-make-user-specific-pre-post-build-events-in-visual-studio-proj

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!