0

I want to be able to drag .cs files into my project on a per account basis. So I have

<Compile Include="Controls\MyControl.ascx.cs">

then for accounts 001 or 002 I would add an extra line

<Compile Include="Accounts\001\Controls\MyControl.ascx.cs">

OR

<Compile Include="Accounts\002\Controls\MyControl.ascx.cs">

This will allow me to override classes based on the account I am running the project for.

Is it safe to modify the CSPROJ file in this way or will visual studio overwrite my changes when I add a new file or dependency?

Also, is my approach to the problem reasonable?

webnoob
  • 15,747
  • 13
  • 83
  • 165
  • You can modify the file and VS will "cache" the new changes when it loads. The CSPROJ is a read/write file, not a write-only (like, say, a t9 output file). – Brad Christie Jul 09 '13 at 14:45
  • How about my approach to the problem? Does it seem reasonable? – webnoob Jul 09 '13 at 14:46
  • you could probably get really sophisticated and create a a PreBuild event that modifies the file based on a SYMBOL or other circumstance, but I don't know enough about when "Accounts" comes in to play to make that judgement call. – Brad Christie Jul 09 '13 at 14:50
  • @BradChristie - Thanks for that. As it stands I store the Account number in the `web.config` file. Could I use this information in the PreBuild event? – webnoob Jul 09 '13 at 15:09
  • Have a look at http://stackoverflow.com/questions/6523008/visual-studio-2010-conditional-references – Brad Christie Jul 09 '13 at 15:29

3 Answers3

3

A csproj file is basically just an MSBuild script. It is OK to modify it. In your case you would typically use a variable so that you have just one csproj file i.e.:

<Compile Include="Accounts\$(Account)\Controls\MyControl.ascx.cs">

Then the account would be defined as an environment variable or somewhere in your .settings/.targets file depending on where you take it from.

Pawel
  • 31,342
  • 4
  • 73
  • 104
  • This sounds promising. I was going to write a tool to update it automatically. Would you be able to link me to something talking about the `.settings` / `.tragets` file? – webnoob Jul 09 '13 at 14:50
  • Never mind, I am looking on MSDN at the moment. This answers my question and more so thanks for your time. – webnoob Jul 09 '13 at 14:53
0

Visual Studio project files are XML files used by the MSBuild script. The editor keeps them updated for you while your working on your project. If you make changes to them while VS is closed, it will load those changes next time you open your project.

just.another.programmer
  • 8,579
  • 8
  • 51
  • 90
0

If it wasn't safe to manually edit them, I seriously doubt that the option to Edit your project (which opens it as XML) would exist as an option in the context menu of Solution Explorer. (You have to Close the project first to see this option)

Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
  • Safe was a poor choice of word. I just wanted to ensure any changes wouldn't be undone but I see your point. Thanks. – webnoob Jul 09 '13 at 15:08