【问题标题】:My app.config did not transform the value我的 app.config 没有转换值
【发布时间】:2014-02-27 16:49:27
【问题描述】:

在我的 Windows 服务应用程序中,我想通过我的配置对其进行调试。最初我使用的是slowcheetah,但是它不起作用。所以我想手动对其进行改造。 有一个method to do it.

在项目文件中,我有

  <ItemGroup>
     <Content Include="App.config" />
     <Content Include="App.Debug.config">
        <DependentUpon>App.config</DependentUpon>
     </Content>
     <Content Include="App.TestDebug.config">
        <DependentUpon>App.config</DependentUpon>
     </Content>
     <Content Include="App.Release.config">
        <DependentUpon>App.config</DependentUpon>
    </Content>
    <None Include="packages.config">
    </None>
 </ItemGroup>

我也有

 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 <UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
 <Target Name="AfterCompile" Condition="exists('app.$(Configuration).config')">
   <!-- Generate transformed app config in the intermediate directory -->
   <TransformXml Source="app.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="app.$(Configuration).config" />
   <!-- Force build process to use the transformed configuration file from now on. -->
<ItemGroup>
     <AppConfigWithTargetPath Remove="app.config" />
     <AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
     <TargetPath>$(TargetFileName).config</TargetPath>
    </AppConfigWithTargetPath>
</ItemGroup>
</Target>
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
   Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->

在 App.TestDebug.config 中,值为:

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
 <appSettings>
  <add key="veserver" value="xx.xx.xx.221" xdt:Transform="Replace" xdt:Locator="Match(key)"/>

在 App.Debug.config 中,值为:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
    <add key="veserver" value="xx.xx.xx.221" />

在 App.config 中,值为:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<appSettings>
  <add key="veserver" value="xx.xx.xx.222" />

现在我用

调试它

App.TestDebug.config

在C#代码中ConfigurationManager.AppSettings["veserver"]还是

xx.xx.xx.222 这意味着它没有改变价值。它应该是 xx.xx.xx.221

为什么?

【问题讨论】:

    标签: visual-studio msbuild visual-studio-2013 csproj


    【解决方案1】:

    自己寻找解决方案。

    <ItemGroup>
     <Content Include="App.config" />
     <None Include="App.Debug.config">
        <DependentUpon>App.config</DependentUpon>
     </None>
     <None Include="App.TestDebug.config">
        <DependentUpon>App.config</DependentUpon>
     </None>
     <None Include="App.Release.config">
        <DependentUpon>App.config</DependentUpon>
    </None>
    <None Include="packages.config">
    </None>
    

    改变

    内容

    .

    【讨论】:

      猜你喜欢
      • 2021-07-08
      • 2011-09-05
      • 2018-08-13
      • 2012-02-09
      • 2014-04-03
      • 2012-08-22
      • 2012-04-03
      • 1970-01-01
      • 2013-03-20
      相关资源
      最近更新 更多