1、创建对应configuration的App.config文件,比如:App.Debug.config、App.Release.config。

2、编辑项目文件,将App.*.config文件的Build Action修改为Content,参考如下:

<Content Include="App.config" />
<Content Include="App.Debug.config">
<DependentUpon>App.config</DependentUpon>
</Content>
<Content Include="App.Publish.config">
<DependentUpon>App.config</DependentUpon>
</Content>
<Content Include="App.Release.config">
<DependentUpon>App.config</DependentUpon>
</Content>

3、在</Project>标签前加入以下配置:

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="AfterCompile" Condition="exists('app.$(Configuration).config')">
<TransformXml Source="app.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="app.$(Configuration).config" />
<ItemGroup>
<AppConfigWithTargetPath Remove="app.config" />
<AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
<TargetPath>$(TargetFileName).config</TargetPath>
</AppConfigWithTargetPath>
</ItemGroup>
</Target>

重新加载项目,就可以看到App.config和Web.config相同的效果。

如果不想使用各种xdt语法,可以直接指定configuration的App.config:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<AppConfig>App.Release.config</AppConfig>
</PropertyGroup>

使用上下文变量修改为更通用的配置:

<PropertyGroup>
<AppConfig>App.$(Configuration).config</AppConfig>
</PropertyGroup>

App.config使用ASP.NET Web Project的Transformation的更多相关文章

  1. C# 对 App.config的appSettings节点数据进行加密

    .NET平台下的Winform和Asp.net的配置文件默认都是明文保存的,本文使用的是.Net自身如何加密配置文件,不包含自定义的加密规则 但.Net是提供了直接对配置文件加密的功能的,使用.Net ...

  2. VS 提示:请考虑使用 app.config 将程序集“XXX”从版本“XX”重新映射到版本“XX”,以解决冲突并消除警告。

    具体提示如下: 请考虑使用 app.config 将程序集"System.Web.Http.WebHost, Culture=neutral, PublicKeyToken=31bf3856 ...

  3. [C#.Net]对WinForm应用程序的App.config的使用及加密

    我们在写C#应用程序时,在工程文件中放置一个app.config,程序打包时,系统会将该配置文件自动编译为与程序集同名的.exe.config 文件.作用就是应用程序安装后,只需在安装目录中找到该文件 ...

  4. C# 对WinForm应用程序的App.config的使用及加密

    原文地址:http://blog.163.com/zhou_zzq/blog/static/1019622120137621739874/   我们在写C#应用程序时,在工程文件中放置一个app.co ...

  5. C# 对WinForm应用程序的App.config的加密

    默认情况下,我们需要对App.config文件里的connectionStrings片断进行加密处理,ASP.NET IIS 注册工具 (Aspnet_regiis.exe)可以胜任这个工作,但这个工 ...

  6. 水果项目第3集-asp.net web api开发入门

    app后台开发,可以用asp.net webservice技术. 也有一种重量级一点的叫WCF,也可以用来做app后台开发. 现在可以用asp.net web api来开发app后台. Asp.net ...

  7. ASP.NET Web Projects

    https://msdn.microsoft.com/en-us/library/ywdtth2f.aspx The topics in this section describe how to cr ...

  8. C#/ASP.NET应用程序配置文件app.config/web.config的增、删、改操作

    原文 http://www.cnblogs.com/codealone/archive/2013/09/22/3332607.html 应用程序配置文件,对于asp.net是 web.config,对 ...

  9. C#/ASP.NET应用程序配置文件app.config/web.config的增、删、改操作,无法为请求的 Configuration 对象创建配置文件。

    应用程序配置文件,对于asp.net是 web.config,对于WINFORM程序是 App.Config(ExeName.exe.config). 配置文件,对于程序本身来说,就是基础和依据,其本 ...

随机推荐

  1. memcached监控工具

    最简单和最直接的方式是在启动memcached的时候加入-vv参数,从而在控制台打印每次客户端的请求和相应,这非常适合开发.另外一种较为直接的方式是通过telnet进行查看,例如:若server为本机 ...

  2. 关于WSDL的理解

    WSDL是由types, message, portType组成. 而binding, service则是具体的绑定. portType有哪些operation. 然后是portType的Endpoi ...

  3. Java华氏转摄氏

    package test; import java.util.Scanner; public class temperature { public static void main(String[] ...

  4. OSG 坑爹的Android example

    本人3D编程方面超级菜鸟,因为项目需要,接触了一些Open Scene Graph(OSG)引擎的相关编程工作.首先我得承认,OSG这个引擎超级牛,无论是渲染效果和效率,都没的说,很棒.但是,OSG提 ...

  5. Window.Open()方法详细的参数说明及技巧。

    Window.Open()方法详细的参数说明及技巧. 一.window.open()支持环境: JavaScript1.0+/JScript1.0+/Nav2+/IE3+/Opera3+ 二.基本语法 ...

  6. ASP.net在网页上显示当前时间,利用AJAX不刷新网页

    前台页面代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default. ...

  7. Thinkphp5 Route用法

    域名路由:domain 1.application/router.php 文件位置,吧一下代码放进去就可以了 use think\Route; Route::domain('app.tp5a.com' ...

  8. [转载]Android 生成keystore,两种方式

    Refer : http://blog.csdn.net/ms03001620/article/details/8490314 一.eclipse 中生成android keystore 建立任意一个 ...

  9. [Unity官方文档翻译]Primitive and Placeholder Objects Unity原生3D物体教程

    Primitive and Placeholder Objects 原始的基础物体 Unity can work with 3D models of any shape that can be cre ...

  10. Hibernate_day04讲义_使用Hibernate完成对客户查询的优化