Using transformed Web.config with IIS Express during debug

rwkiii

I have a Visual Studio application that has multiple Solution Configurations. There is a Web.config transform file for each configuration. For example, Web.Debug.config, Web.Release.config, etc.

We also have a couple of developers working on this project that have nonstandard SQL Express instance names due to the way they installed SQL Express and rather than having them continually editing Web.Debug.config to run in their environment I have setup a Solution Configuration for each of them and added the following to the very bottom of the .csproj file. This code does work in that it triggers the creation of Web.config and MyWebApp.dll.config in the VS /obj/Debug-DeveloperName/ folder.

The transformed .config files are perfect, but IIS Express still uses the root Web.config (not transformed).

Is there a way to get IIS Express to use these transformed Web.config files while debugging locally?

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

<Target 
    Name="AfterCompile" 
    Condition="exists('Web.$(Configuration).config')">

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

Using the web application's Web.Debug.Config works for most of us, but not all.

There must be a way of getting IIS Express to use the transformed Web.Debug-DeveloperName.config during local debug?

Does the transformed Web.config have to be copied into a different folder?

Martin Brabec

I faced this problem before and I found a solution. Unfortunately, the solution is not based on forcing IIS to use different name of the config, but if you follow steps below, you will just select the configuration and run you app (which is ewhat you need I think). The Web.config transform will occur before build and it will replace the original Web.config by the transformad one. Then, when the deployment (to local IIS Express) begins, it will already use the transformed one.

Here is step by step how I did this in one project (VS2012):

  1. Right click on the project and select Unload
  2. Right click on it again and select Edit
  3. Go to the bottom of the file and append the follwing to the right over the "" tag (it will be last item)
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\WebApplications\Microsoft.WebApplication.targets" />
<Target Name="BeforeBuild" Condition="'$(PublishProfileName)' == '' And '$(WebPublishProfileFile)' == ''">
    <TransformXml Source="Web.config" Transform="Web.$(Configuration).config" Destination="Web.config" />
</Target>

The condition there is to prevent duplicate transformation when publishing.

  1. Save the file, right click on it and select Reload

Now, everytime you run a build, your Web.config will be transformed according to selected configuration.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

A Renamed WebSite, Web.Config, Log4Net, using IIS Express, using Git version control, in VS2015, failing

From Dev

Web.config is not transformed when debugging code

From Dev

IIS Express (Debug Mode) and HTTPS

From Dev

iis: applicationhost.config in iis express

From Dev

iis: applicationhost.config in iis express

From Dev

How to remove an extension from iis using web.config

From Dev

Run Web Service using IIS Express without Visual Studio

From Dev

Web API 2 CORS IIS Express Debug and No Access-Control-Allow-Origin header

From Dev

ASP.NET 5 web app not running in debug mode in IIS Express

From Dev

TFS 2012 not copying transformed Web.Config to _PublishedWebsite

From Dev

How to get transformed value of key from Web.config

From Dev

Update Azure CSPKG with a transformed web.config post-publish

From Dev

Should the web.config be transformed before or after the MSBuild task?

From Dev

Cannot debug config error during startup

From Dev

How to debug with IIS (not Express) in Visual Studio 2013

From Dev

Unable to launch the IIS Web Server, how to debug

From Dev

Read web.config from library consumed by the webapplicaion deployed using IIS

From Dev

How do I setup an Azure Web Farm on multiple VM's using a shared IIS config

From Dev

How to translate this .htaccess to IIS web.config?

From Dev

Powershell: Updating IIS web.config

From Dev

IIS 7 URL Rewrite and Web.config

From Dev

Powershell: Updating IIS web.config

From Dev

web.config redirect in IIS server

From Dev

IIS url redirect rule in web.config

From Dev

Web.config not being used in IIS for WCF

From Dev

when does web.debug.config apply?

From Dev

Set web config debug to false and broke project

From Dev

Common output directory, Web Applications and IIS Express

From Dev

"Unable to launch the IIS Express Web server" error

Related Related

  1. 1

    A Renamed WebSite, Web.Config, Log4Net, using IIS Express, using Git version control, in VS2015, failing

  2. 2

    Web.config is not transformed when debugging code

  3. 3

    IIS Express (Debug Mode) and HTTPS

  4. 4

    iis: applicationhost.config in iis express

  5. 5

    iis: applicationhost.config in iis express

  6. 6

    How to remove an extension from iis using web.config

  7. 7

    Run Web Service using IIS Express without Visual Studio

  8. 8

    Web API 2 CORS IIS Express Debug and No Access-Control-Allow-Origin header

  9. 9

    ASP.NET 5 web app not running in debug mode in IIS Express

  10. 10

    TFS 2012 not copying transformed Web.Config to _PublishedWebsite

  11. 11

    How to get transformed value of key from Web.config

  12. 12

    Update Azure CSPKG with a transformed web.config post-publish

  13. 13

    Should the web.config be transformed before or after the MSBuild task?

  14. 14

    Cannot debug config error during startup

  15. 15

    How to debug with IIS (not Express) in Visual Studio 2013

  16. 16

    Unable to launch the IIS Web Server, how to debug

  17. 17

    Read web.config from library consumed by the webapplicaion deployed using IIS

  18. 18

    How do I setup an Azure Web Farm on multiple VM's using a shared IIS config

  19. 19

    How to translate this .htaccess to IIS web.config?

  20. 20

    Powershell: Updating IIS web.config

  21. 21

    IIS 7 URL Rewrite and Web.config

  22. 22

    Powershell: Updating IIS web.config

  23. 23

    web.config redirect in IIS server

  24. 24

    IIS url redirect rule in web.config

  25. 25

    Web.config not being used in IIS for WCF

  26. 26

    when does web.debug.config apply?

  27. 27

    Set web config debug to false and broke project

  28. 28

    Common output directory, Web Applications and IIS Express

  29. 29

    "Unable to launch the IIS Express Web server" error

HotTag

Archive