如何在内置的visual studio调试器服务器中使用Web.debug.config?

时间:2022-08-09 00:09:30

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

如何在visual studio 2010内置调试器中合并和使用Web.debug.config?

7 个解决方案

#1


89  

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.

如果您遇到此问题,请进行投票,以便尽快修复。

#2


34  

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

这实际上很简单,不管你信不信,这似乎是VS的设计方式。

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

在包含web.config的项目的.csproj文件的结束“Project”标记之前,逐字添加以下行。

<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.

将以下行逐字添加到包含web.config文件的项目的项目属性中的post-build事件。对要运行转换的每个构建配置执行此操作。

"$(MSBUILDBINPATH)\msbuild" "$(ProjectPath)" /t:Transform /p:Configuration=$(ConfigurationName);Platform=AnyCPUxcopy "$(ProjectDir)obj\$(ConfigurationName)\Web.Config" "$(ProjectDir)". /F /R /Y

#3


12  

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.

我以更简单的方式解决了这个问题,在.csproj文件的末尾添加了这个,就在标记之前。这与keitn的答案类似,区别在于它不使用post build事件。

<Target Name="BeforeBuild">    <TransformXml Source="Web.config" Transform="Web.$(Configuration).config" Destination="Web.config" /></Target>

#4


2  

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.

我不想更新我的项目中的web.config只是最后在bin文件夹中的那个,所以这就是我做的方式。

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

将以下内容添加到.csproj的末尾(在最终结束项目标记之前)

<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

然后添加以下post构建步骤

"$(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.

这意味着当您构建转换时,会从调试/发布配置到输出bin目录中的WebsiteName.Config文件,从而不会干扰项目中的主web.config。

#5


1  

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:

阅读了很多类似的帖子,并且文件无法被覆盖或web.config无法访问,因为它是只读的,这就是我为我工作的内容:

  <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.

它作为BeforeBuild目标运行。

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.

我只希望它在某个配置下运行(另一种调试环境),这就是我有条件的原因。通过Web部署部署时,发布目标会启动,我不需要运行此目标。

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.

我不想记得检查web.config(仅在我完成时撤消它)所以我在开始转换之前检查web.config。如果您不使用TFS,则可以删除此行。

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)

因为VS(2010)\ msbuild不想放弃Source web.config我使用临时文件(感谢这篇文章的信息:http://www.diaryofaninja.com/blog/2011/09/ 14 /使用定制-webconfig-变换合的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.

我尝试添加一个命令来删除TempWeb.config,但VS \ msbuild不想放弃它。我可以忍受它,因为它没有被添加到TFS。

#6


0  

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

我知道这是旧的,但我面临同样的问题。我们有测试,暂存,实时配置,用于替换默认Web.config中的端点,连接字符串等

However I would do the following:

但是,我会做以下事情:

  • Right click on the desired transform config (e.g. Web.Live.config)
  • 右键单击所需的转换配置(例如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
    • CTRL + A + CTRL + C.

  • 从右边复制所有内容(这是Web.config在转换时的外观)CTRL + A + CTRL + C.

  • Open Web.config file (default one)
  • 打开Web.config文件(默认一个)

  • Select everything (CTRL+A) and paste it in (CTRL+V)
  • 选择所有内容(CTRL + A)并将其粘贴到(CTRL + V)

  • Run

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

当你掌握它时,它并不是很多步骤而且很快完成。希望这可以帮助。 :)

#7


-1  

@ologesa:Your solution needs write access to the original Web.config (you must check-out in TFS).The better solution is to directly generate the Web.config in the bin folder like keitn does this. When we combine keitn's and your solution we get this one:

@ologesa:您的解决方案需要对原始Web.config的写入权限(您必须在TFS中签出)。更好的解决方案是直接在bin文件夹中生成Web.config,就像keitn这样做。当我们将keitn和您的解决方案结合起来时,我们得到了这个:

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

#1


89  

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.

如果您遇到此问题,请进行投票,以便尽快修复。

#2


34  

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

这实际上很简单,不管你信不信,这似乎是VS的设计方式。

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

在包含web.config的项目的.csproj文件的结束“Project”标记之前,逐字添加以下行。

<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.

将以下行逐字添加到包含web.config文件的项目的项目属性中的post-build事件。对要运行转换的每个构建配置执行此操作。

"$(MSBUILDBINPATH)\msbuild" "$(ProjectPath)" /t:Transform /p:Configuration=$(ConfigurationName);Platform=AnyCPUxcopy "$(ProjectDir)obj\$(ConfigurationName)\Web.Config" "$(ProjectDir)". /F /R /Y

#3


12  

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.

我以更简单的方式解决了这个问题,在.csproj文件的末尾添加了这个,就在标记之前。这与keitn的答案类似,区别在于它不使用post build事件。

<Target Name="BeforeBuild">    <TransformXml Source="Web.config" Transform="Web.$(Configuration).config" Destination="Web.config" /></Target>

#4


2  

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.

我不想更新我的项目中的web.config只是最后在bin文件夹中的那个,所以这就是我做的方式。

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

将以下内容添加到.csproj的末尾(在最终结束项目标记之前)

<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

然后添加以下post构建步骤

"$(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.

这意味着当您构建转换时,会从调试/发布配置到输出bin目录中的WebsiteName.Config文件,从而不会干扰项目中的主web.config。

#5


1  

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:

阅读了很多类似的帖子,并且文件无法被覆盖或web.config无法访问,因为它是只读的,这就是我为我工作的内容:

  <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.

它作为BeforeBuild目标运行。

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.

我只希望它在某个配置下运行(另一种调试环境),这就是我有条件的原因。通过Web部署部署时,发布目标会启动,我不需要运行此目标。

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.

我不想记得检查web.config(仅在我完成时撤消它)所以我在开始转换之前检查web.config。如果您不使用TFS,则可以删除此行。

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)

因为VS(2010)\ msbuild不想放弃Source web.config我使用临时文件(感谢这篇文章的信息:http://www.diaryofaninja.com/blog/2011/09/ 14 /使用定制-webconfig-变换合的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.

我尝试添加一个命令来删除TempWeb.config,但VS \ msbuild不想放弃它。我可以忍受它,因为它没有被添加到TFS。

#6


0  

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

我知道这是旧的,但我面临同样的问题。我们有测试,暂存,实时配置,用于替换默认Web.config中的端点,连接字符串等

However I would do the following:

但是,我会做以下事情:

  • Right click on the desired transform config (e.g. Web.Live.config)
  • 右键单击所需的转换配置(例如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
    • CTRL + A + CTRL + C.

  • 从右边复制所有内容(这是Web.config在转换时的外观)CTRL + A + CTRL + C.

  • Open Web.config file (default one)
  • 打开Web.config文件(默认一个)

  • Select everything (CTRL+A) and paste it in (CTRL+V)
  • 选择所有内容(CTRL + A)并将其粘贴到(CTRL + V)

  • Run

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

当你掌握它时,它并不是很多步骤而且很快完成。希望这可以帮助。 :)

#7


-1  

@ologesa:Your solution needs write access to the original Web.config (you must check-out in TFS).The better solution is to directly generate the Web.config in the bin folder like keitn does this. When we combine keitn's and your solution we get this one:

@ologesa:您的解决方案需要对原始Web.config的写入权限(您必须在TFS中签出)。更好的解决方案是直接在bin文件夹中生成Web.config,就像keitn这样做。当我们将keitn和您的解决方案结合起来时,我们得到了这个:

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