zoukankan      html  css  js  c++  java
  • App.config使用ASP.NET Web Project的Transformation

    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)MicrosoftVisualStudiov10.0WebMicrosoft.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>
  • 相关阅读:
    JavaScript设计模式-21.命令模式
    JavaScript设计模式-20.责任链模式
    JavaScript设计模式-18.享元模式
    JavaScript设计模式-19.代理模式
    JavaScript设计模式-17.装饰者模式(下)
    JavaScript设计模式-16.装饰者模式(上)
    面向对象之集合ArrayList
    面向对象之继承
    字符串的添加与切割~~~
    面向对象中构造函数的小练习
  • 原文地址:https://www.cnblogs.com/junchu25/p/3891810.html
Copyright © 2011-2022 走看看