我正在对VS 2017社区开发WPF应用程序。
我已经下载了slowcheetah,所以这是我的
app.debug.config
<?xml version="1.0" encoding="utf-8" ?>
<!-- For more information on using transformations
see the web.config examples at http://go.microsoft.com/fwlink/?LinkId=214134. -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="application.log" />
<remove name="Default" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
app.release.config
<?xml version="1.0" encoding="utf-8" ?>
<!-- For more information on using transformations
see the web.config examples at http://go.microsoft.com/fwlink/?LinkId=214134. -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
</startup>
</configuration>
现在,无论我选择"调试"或"释放",app.config都没有任何更改。此外,单击"预览转换到两个文件"始终向我展示app.config原始内容。我在哪里错了?
您需要在配置文件上启用变换。右键单击您的项目,选择卸载项目。右键再次单击选择编辑xxx.csproj 。
滚动到XML文件的底部。
看起来应该像:
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir).nugetNuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir).nugetNuGet.targets'))" />
<Error Condition="!Exists('..packagesSlowCheetah.2.5.48buildSlowCheetah.targets')" Text="$([System.String]::Format('$(ErrorText)', '..packagesSlowCheetah.2.5.48buildSlowCheetah.targets'))" />
<Error Condition="!Exists('..packagesBuildWebCompiler.1.11.359buildBuildWebCompiler.targets')" Text="$([System.String]::Format('$(ErrorText)', '..packagesBuildWebCompiler.1.11.359buildBuildWebCompiler.targets'))" />
</Target>
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
<Import Project="$(SlowCheetahTargets)" Condition="Exists('$(SlowCheetahTargets)')" Label="SlowCheetah" />
<Import Project="..packagesSlowCheetah.2.5.48buildSlowCheetah.targets" Condition="Exists('..packagesSlowCheetah.2.5.48buildSlowCheetah.targets')" />
<Import Project="..packagesBuildWebCompiler.1.11.359buildBuildWebCompiler.targets" Condition="Exists('..packagesBuildWebCompiler.1.11.359buildBuildWebCompiler.targets')" />
插入以下XML:
<Target Name="BeforeBuild">
<TransformXml Source="App.config" Transform="App.$(Configuration).config" Destination="App.config" />
</Target>
所以现在看起来像
<Import Project="$(SolutionDir).nugetNuGet.targets" Condition="Exists('$(SolutionDir).nugetNuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir).nugetNuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir).nugetNuGet.targets'))" />
<Error Condition="!Exists('..packagesSlowCheetah.2.5.48buildSlowCheetah.targets')" Text="$([System.String]::Format('$(ErrorText)', '..packagesSlowCheetah.2.5.48buildSlowCheetah.targets'))" />
<Error Condition="!Exists('..packagesBuildWebCompiler.1.11.359buildBuildWebCompiler.targets')" Text="$([System.String]::Format('$(ErrorText)', '..packagesBuildWebCompiler.1.11.359buildBuildWebCompiler.targets'))" />
</Target>
<Target Name="BeforeBuild">
<TransformXml Source="App.config" Transform="App.$(Configuration).config" Destination="App.config" />
</Target>
<Target Name="AfterBuild">
</Target>
<Import Project="$(SlowCheetahTargets)" Condition="Exists('$(SlowCheetahTargets)')" Label="SlowCheetah" />
<Import Project="..packagesSlowCheetah.2.5.48buildSlowCheetah.targets" Condition="Exists('..packagesSlowCheetah.2.5.48buildSlowCheetah.targets')" />
<Import Project="..packagesBuildWebCompiler.1.11.359buildBuildWebCompiler.targets" Condition="Exists('..packagesBuildWebCompiler.1.11.359buildBuildWebCompiler.targets')" />
右键单击选择重新加载项目。重建。
还确保您的配置文件正确嵌套,它们应该看起来像这样:
<Content Include="App.config">
<SubType>Designer</SubType>
</Content>
<Content Include="App.Debug.config">
<DependentUpon>App.config</DependentUpon>
</Content>
<Content Include="App.Release.config">
<DependentUpon>App.config</DependentUpon>
</Content>