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.

1 Answer 1

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)

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for the feedback. Can you please explain point 1 in further detail please?
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 ...
You can add the following node inside the <Project> node in your project file (preferrably towards the end): ` <Target Name="BeforeBuild"> <Exec Command="if exist web.config del /f web.config" /> <Copy SourceFiles="web.MyProjectName.config" DestinationFiles="web.config" /> </Target>`
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?
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.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.