How can I use Web.debug.config in the built-in visual studio debugger server?

前端 未结 7 533
花落未央
花落未央 2020-11-27 02:34

How can I merge and make use of Web.debug.config in visual studio 2010 built-in debugger?

相关标签:
7条回答
  • 2020-11-27 03:13

    I had solved this in a simpler way, by adding this at the end of the .csproj file, right before the tag. This is similar to keitn's answer, with the difference that it doesn't use a post build event.

    <Target Name="BeforeBuild">
        <TransformXml Source="Web.config" Transform="Web.$(Configuration).config" Destination="Web.config" />
    </Target>
    
    0 讨论(0)
  • 2020-11-27 03:20

    This is a known bug. That feature can be used right now only as part of the deploy process.

    https://connect.microsoft.com/VisualStudio/feedback/details/523221/have-web-debug-config-apply-during-development

    Please upvote it, if you encounter this too, so this will be fixed ASAP.

    0 讨论(0)
  • 2020-11-27 03:23

    After reading many similar posts and having problems with files not being able to be overwritten or web.config not being accessible because it is read only this is what I got working for me:

      <Target Name="BeforeBuild" Condition="$(Configuration) == 'MyAltDebugConfiguration'">
        <ItemGroup>
          <OriginalWebConfig Include="$(ProjectDir)Web.config"/>
          <TempWebConfig Include="$(ProjectDir)TempWeb.config"/>
        </ItemGroup>
        <Exec Command="&quot;$(DevEnvDir)tf.exe&quot; checkout &quot;$(ProjectDir)Web.config&quot;" />
        <Copy SourceFiles="@(OriginalWebConfig)" DestinationFiles="@(TempWebConfig)" />
        <TransformXml Source="$(ProjectDir)TempWeb.config"
                                Transform="Web.$(Configuration).config"
                                Destination="Web.config" />
      </Target>
    

    Notes:

    This runs as the BeforeBuild target.

    I only want it to run under a certain configuration (an alternative debug environment) and so that is why I have the Condition. When deploying via web deploy the publishing target kicks in and I don't need this target to run.

    I don't want to have to remember to check out web.config (only to undo it when I am done) so I check web.config out before beginning the transform. If you aren't using TFS you can remove this line.

    Because VS (2010) \ msbuild doesn't want to let go of the Source web.config I use a temp file (thanks to this article for the info: http://www.diaryofaninja.com/blog/2011/09/14/using-custom-webconfig-transformations-in-msbuild)

    I tried adding a command to delete the TempWeb.config but VS \ msbuild doesn't want to let go of it. I can live with it as it doesn't get added to TFS.

    0 讨论(0)
  • 2020-11-27 03:29

    I didn't want to update the web.config in my project just the one that ends up in the bin folder so here is how I did it.

    Add the following to the end of .csproj (just before the final closing project tag)

    <Target Name="Transform">
        <MakeDir Directories="bin" Condition="!Exists('bin')" />
        <TransformXml Source="Web.Config" Transform="Web.$(Configuration).config" Destination="bin\$(TargetFileName).config" StackTrace="true" />
      </Target>
    

    Then add the following post build step

    "$(MSBUILDBINPATH)\msbuild" "$(ProjectPath)" /t:Transform /p:Configuration=$(ConfigurationName);Platform=AnyCPU
    

    This means that when you build a transform takes place from the debug/release config to WebsiteName.Config file in the output bin directory thus not interfering with the main web.config in the project.

    0 讨论(0)
  • 2020-11-27 03:32

    This is actually quite simple to do and, believe it or not, it seems this is the way VS is designed to work.

    Add the following lines verbatim right before the closing "Project" tag of the .csproj file of the project that contains web.config.

    <UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" />
    <Target Name="Transform">
        <MakeDir Directories="obj\$(Configuration)" Condition="!Exists('obj\$(Configuration)')" />
        <TransformXml Source="Web.Config" Transform="Web.$(Configuration).config" Destination="obj\$(Configuration)\Web.config" StackTrace="true" />
    </Target>
    

    Put the following lines verbatim to the post-build event in the project properties of the project that contains the web.config file. Do this for each build configuration you want the transformations to run for.

    "$(MSBUILDBINPATH)\msbuild" "$(ProjectPath)" /t:Transform /p:Configuration=$(ConfigurationName);Platform=AnyCPU
    xcopy "$(ProjectDir)obj\$(ConfigurationName)\Web.Config" "$(ProjectDir)". /F /R /Y
    
    0 讨论(0)
  • 2020-11-27 03:36

    I know this is old, but I'm facing the same problem. We have Test, Staging, Live configs that replace endpoints, connection strings etc. from the default Web.config

    However I would do the following:

    • Right click on the desired transform config (e.g. Web.Live.config)
    • Click on "Preview Transform"
    • Copy everything from right (it's how the Web.config looks with the transformation)
      • CTRL+A + CTRL+C
    • Open Web.config file (default one)
    • Select everything (CTRL+A) and paste it in (CTRL+V)
    • Run

    It's not that many steps and is done pretty quickly when you get a hang of it. Hope this helps. :)

    0 讨论(0)
提交回复
热议问题