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 爬虫 解决escape问题
    python 爬虫 重复下载 二次请求
    iOS开发-消息通知机制(NSNotification和NSNotificationCenter)
    iOS开发-UITableView自定义Cell
    iOS开发-自定义UIAlterView(iOS 7)
    iOS开发-CocoaPods实战
    iOS开发-UICollectionView实现瀑布流
    iOS开发-UITabBarController详解
    iOS 开发-Certificate、App ID和Provisioning Profile之间的关系
    iOS开发-View中frame和bounds区别
  • 原文地址:https://www.cnblogs.com/junchu25/p/3891810.html
Copyright © 2011-2022 走看看