Is there a way to do custom pre / post build events in Visual Studio projects?

I am currently using the 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 only, so I would rather have it in the * .csproj.user file instead of the * .csproj file. I tried to copy the responsible elements from * .csproj to * .csproj.user, but this did not work.

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

To provide more context, this is not a reference to the project. I copy my assembly to the application directory, which loads assemblies at runtime. (Think plugins)

+6
source share
4 answers

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

A slightly longer answer is sorting. You can theoretically have specific build events triggered for individual users, but they will still be in the csproj file. You can fire external events in assemblies and then allow these external events to be triggered depending on which user is executing them (like a script).

If this is for debugging only, I would just insert them, build them, and pull them out before uploading them to your version control system.

+6
source

You can use a custom target construct that has a condition caused by an environment variable. Then set only this variable on your computer.

+2
source

Use if statement and environment variable (in case of double quotes)

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

Pre- / Post-build events are stored in the project file. VS does not provide any parameters.

You can enter a custom (external) tool to perform such copying, although you can call it from the menu, or macros and call it too.

0
source

Source: https://habr.com/ru/post/921499/


All Articles