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>
  • 相关阅读:
    爬虫入门
    读写文件操作
    列表的操作
    课后习题小练
    Python切片
    逗号的麻烦
    字符串学与练
    Turtle的学习
    FTL(FreeMarker)基础
    java反射机制基础
  • 原文地址:https://www.cnblogs.com/junchu25/p/3891810.html
Copyright © 2011-2022 走看看