Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can achieve the effect you're looking for by using the BeforeBuild and AfterBuild targets available in the .csproj file. The VS.NET IDE will execute these targets when doing a Build or a Rebuild, so you can use them to execute the web.config transforms. Since you'll need to do a web.config transform and then overwrite the actual web.config file, you'll need to rely on a new file called web.default.config to store the base web.config data.</p> <p>I tried this out in a test project, here were the changes I made to the .csproj file:</p> <pre><code>&lt;Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" /&gt; &lt;ProjectExtensions&gt; ... &lt;/ProjectExtensions&gt; &lt;Target Name="BeforeBuild"&gt; &lt;Copy SourceFiles="$(ProjectDir)web.default.config" DestinationFiles="$(ProjectDir)web.config" /&gt; &lt;/Target&gt; &lt;Target Name="AfterBuild" Condition="$(FirstRun) != 'false'"&gt; &lt;MSBuild Projects="$(MSBuildProjectFile)" Targets="TransformWebConfig" Properties="FirstRun=false;" /&gt; &lt;Sleep Milliseconds="2000" /&gt; &lt;Copy SourceFiles="$(ProjectDir)obj\$(ConfigurationName)\TransformWebConfig\transformed\web.config" DestinationFiles="$(ProjectDir)web.config" /&gt; &lt;/Target&gt; </code></pre> <p>I had to manually add these to the .csproj file (I used Notepad++). As far as I can tell there is no way to add these instructions through the VS.NET IDE. You need to supply the conditional on the AfterBuild to keep from having a circular reference, as the call to MSBuild will rerun the build to generate the web.config transform.</p> <p>Basically what we're doing is copying the web.default.config file (our base template) over the existing web.config before we start to build, and then we use MSBuild to generate a web.config for whatever configuration we're building. After the transform is complete, we use a Copy task to take the transformed file and copy it over to the web.config file in the web root. One issue I occasionally ran into was a file in use error when trying to overwrite the web.config after the transform was complete. Adding a Sleep task (from <a href="http://msbuildtasks.tigris.org/" rel="nofollow noreferrer">MSBuildCommunityTasks</a>) after the MSBuild task took care of that issue.</p> <p>I only tested this approach using the built in ASP.NET server, not IIS, so YMMV but I feel like this is a workable solution.</p> <p>The FirstRun idea came from this <a href="https://stackoverflow.com/questions/2811556/how-to-use-the-new-vs-2010-configuration-transforms-and-apply-them-to-other-conf">post</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload