blachniet
blachniet

Reputation: 4553

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

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)

Upvotes: 10

Views: 5527

Answers (4)

Micah Armantrout
Micah Armantrout

Reputation: 6971

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

Upvotes: 4

nyxthulhu
nyxthulhu

Reputation: 9752

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.

Upvotes: 8

rerun
rerun

Reputation: 25505

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

Upvotes: 2

abatishchev
abatishchev

Reputation: 100288

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.

Upvotes: 1

Related Questions