slowcheetah new asp.net mvc transform not working

1.8k Views Asked by At

I think I must be missing something with slowcheetah. I created a new asp.net mvc3 application. Added one appsetting to web.config with a default value. Then I added one transform to each the debug and release config files. I also created a view that reads in this value. When I preview the transform the transformation works fine. My understanding was that if I run the project in release mode then the project would read in the app setting from the release transformation, and if I ran the project in debug mode it would read in the app setting from the debug configuration.

Here is the relevant part of web.config

<appSettings>      
    <add key="cheetah_val" value="default_val"/>
  </appSettings>

here is web.debug.config

<?xml version="1.0"?>

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">  

  <appSettings>
    <add key="cheetah_val" value="debug_val" xdt:Transform="Replace" xdt:Locator="Match(key)"/>

  </appSettings>
  <system.web>

  </system.web>
</configuration>

here is web.release.config

<?xml version="1.0"?>

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">

  <appSettings>
    <add key="cheetah_val" value="release_val" xdt:Transform="Replace" xdt:Locator="Match(key)"/>

  </appSettings>
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />

  </system.web>
</configuration>

The HomeController.cs

public class HomeController : Controller
    {
        public ActionResult Index()
        {    

            ViewBag.CheetahMessage = System.Configuration.ConfigurationManager.AppSettings["cheetah_val"];   
            return View();
        }          
    }

And index.cshtml

@{
    ViewBag.Title = "Home Page";
}

<h2>@ViewBag.CheetahMessage</h2>

I would expect the output to be release_val in release mode and debug_val in debug mode. What am I doing wrong? Or am I missing something important? For web sites does the F5 functionality not work? For web sites do I have to actually publish this to get the transformation to work?

2

There are 2 best solutions below

4
On BEST ANSWER

My understanding was that if I run the project in release mode then the project would read in the app setting from the release transformation, and if I ran the project in debug mode it would read in the app setting from the debug configuration.

That was also my assumption when I originally read about and downloaded slowcheetah.

For web sites do I have to actually publish this to get the transformation to work?

AFAIK, you have to publish for both web sites and web application projects to get the transformation to work. Slowcheetah doesn't even do this, it's the VS publish tool that does it. Slowcheetah only lets you preview the transforms.

If I'm wrong on this someone please speak up, because I too would like to be able to run transforms when debugging locally in IIS Express.

One possible solution could be to set up real IIS on your machine to serve from your publish directory. Then when you want to see how the transforms affect behavior, you can publish the web to IIS and use it to view the site. I don't think this would let you attach a debugger though.

1
On

My understanding is that SlowCheetah is for the App.Config not the web.config

Doing the same thing for web.config should already be a standard part of VS2010.

Here's Scott Hanselman talking about it (look at 6 min 20 seconds) http://www.hanselman.com/blog/WebDeploymentMadeAwesomeIfYoureUsingXCopyYoureDoingItWrong.aspx

And this is him writing about SlowCheetah http://www.hanselman.com/blog/SlowCheetahWebconfigTransformationSyntaxNowGeneralizedForAnyXMLConfigurationFile.aspx

I used SlowCheetah for my app.config and it works perfectly.