Lai*_*Lai 6 asp.net visual-studio visual-studio-2013
在Visual Studio 2013中使用"发布网站"功能时.如何排除发布web.config以使其不会覆盖服务器web.config?
除VS版本外,问题与以下内容相同.
使用Visual Web Developer Express发布时如何排除web.config?
但是,其解决方案不适用于VS2013.在VS2013中找不到"构建操作"选项.设置"ExcludeFilesFromDeployment"会导致编译问题.
Abh*_*Dey 30
只需选择web.config属性并将"Build Action"更改为"None"并将"Copy To Output Directory"更改为"Do not copy"
我知道这是一篇旧帖子,有旧答案,但对我来说,所描述的两种解决方案都是错误的。
Web.config 风格在操作环境凭据时会引发安全风险,而“Build Action”="None" 解决方案打破了在本地调试项目的可能性,因为 Web.Config 文件永远不会出现在“bin”目录中.
更清洁的解决方案是这里描述的内容:
这基本上是创建一个ProjectName .wpp.targets 文件,其中包含发布项目时要排除的文件/文件夹列表。
要从名为Blog的项目中删除Web.config,您需要创建一个名为Blog.wpp.targets的文件,其内容如下:
文件: Blog.wpp.targets
<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="4.0"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ExcludeFromPackageFiles Include=".\Web.config">
<FromTarget>Blog.wpp.targets</FromTarget>
</ExcludeFromPackageFiles>
</ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
无需更改项目或 .csproj 文件中的任何内容。
排除 web.config 文件不是推荐的解决方案。您应该使用 web.config 转换文件,这是web.xxx.config文件。

当您发布网站时,Visual Studio 会将您本地的 web.config 与相应的web.xxx.config文件合并
配置转换文件使用 XDT(XML 文档转换)语法。例如,如果您想更改连接字符串,您可以在转换文件中使用这段代码:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="MyDB"
connectionString="value for the deployed Web.config file"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
有关更多示例和信息,请参阅使用 Visual Studio 进行 Web 项目部署的 Web.config 转换语法。
2020 并使用 AspCore 项目,然后尝试在 .csproj 中添加以下代码:
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13591 次 |
| 最近记录: |