Nick
Nick

Reputation: 4092

Different custom web servers in VS based off build configuration

In visual studio 2012, you can set a custom web server under

Web project properties -> Web -> Servers -> Use Custom Web Server

The UI doesn't allow this, but is it possible to specify different servers based off the build configuration (debug, release, etc.) in the project file?

enter image description here

Upvotes: 0

Views: 49

Answers (1)

Nick
Nick

Reputation: 4092

It seems that there's no way to do this. I wanted to keep my Debug and Release (and other configuration) builds separate because we were doing things differently in both configurations (for example, minifying resources, etc.). Devs wanted their own config to skip certain projects that they didn't care about and the output differed.

I ended up using web.config transformations to point the web server to the folders that contained the bundle for the given config. We had to accomplish that by manually modifying the csproj file like this:

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.Tasks.dll" />

<!--Generate transformed web.config in the intermediate directory-->
<TransformXml Source="Web.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="Web.$(Configuration).config" />


<!--Force build process to use the transformed configuration file from now on.-->
<ItemGroup>
  <AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
    <TargetPath>Web.config</TargetPath>
  </AppConfigWithTargetPath>
</ItemGroup>

Upvotes: 1

Related Questions