0

I have a Visual Studio 2010 web-application solution I have created. In this solution I have created a new mode in the configuration manager called "MyProjectName". I have created an additional transform (I think you call it). i.e. Web.MyProjectName.config.

When I choose the publish option on the project, I have the "MyProjectName" option selected from the build mode.

However, the Web.MyProjectName.config is not copied to the published folder.

How do I get different Web.config's published depending on what configuration mode I have selected?

Thanks in advance.

Seany84
  • 5,526
  • 5
  • 42
  • 67

1 Answers1

1

You will need to copy your new config file using either of the two options:

  • modify your project file to add a Target Named "BeforeBuild" (or modify if it exists)
  • add a "Pre Build" event

(I prefer the first one)

Arun
  • 2,493
  • 15
  • 12
  • Thanks for the feedback. Can you please explain point 1 in further detail please? – Seany84 Aug 23 '11 at 09:45
  • 1
    Project file actually contains code that is used by MSBuild each time you try to compile your Project. If you open the Project file in text mode (either through a text editor OR using Visual Studio IDE after you right click on the Project + "Unload Project" + "Edit yourprojectfilename.csproj"), you can browse through the contents to see a lot of predefined "Targets". "Targets" tell MSBuild on what you intend to do - Clean/Rebuild/Build/Publish and so on. "Targets" can be thought of as wiring to Events - that is MSBuild will honor what you want to do, if you actually define such events ... – Arun Aug 23 '11 at 17:14
  • 1
    You can add the following node inside the node in your project file (preferrably towards the end): ` ` – Arun Aug 23 '11 at 17:17
  • Thanks. Can this be done in the build events of the Project file. i.e. when I right click on my Project and go to Build Events? – Seany84 Aug 24 '11 at 11:06
  • 1
    Yes it can be done using a PreBuild event. I prefer to go with the 1st option (including "BeforeBuild" Target) because it is specific to MSBuild. I guess PreBuild Events are handled by Visual Studio, which would imply, I will lose my leverage to automate my Build Scripts by having a dependency on IDE. You might have noticed this already (when you edited your Project file with IDE) - the Target tag takes in attributes (like "Condition", "Depends"), that would really give good leverage on channelling your build. – Arun Aug 24 '11 at 16:18
  • Also check this post -http://geekswithblogs.net/dchestnutt/archive/2006/05/30/80113.aspx). He gives some good insight on issues using Build Events. – Arun Aug 24 '11 at 16:19