Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf App.config转换为';t应用于AppName.exe.config_Wpf_Msbuild_Transformation - Fatal编程技术网

Wpf App.config转换为';t应用于AppName.exe.config

Wpf App.config转换为';t应用于AppName.exe.config,wpf,msbuild,transformation,Wpf,Msbuild,Transformation,我在我们的WPF项目中有一个app.config文件,它使用.csproj中的以下构建目标进行转换 <!-- MSbuild Task for transforming app.config based on the configuration settings --> <UsingTask TaskName="TransformXml" AssemblyFile="$(SolutionDir)\packages\MSBuild.Microsoft.Vi

我在我们的WPF项目中有一个app.config文件,它使用.csproj中的以下构建目标进行转换

<!-- MSbuild Task for transforming app.config based on the configuration settings -->
<UsingTask TaskName="TransformXml" 
           AssemblyFile="$(SolutionDir)\packages\MSBuild.Microsoft.VisualStudio.Web.targets.12.0.4\tools\VSToolsPath\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="AfterBuild">
  <!-- Transform the app.config into the correct config file associated to the current build settings -->
  <TransformXml Source="App.config" Transform="App.$(Configuration).config" Destination="$(OutputPath)\App.config" />
  <!-- Bit of .Net to get all folders and subfolders that we want to delete post-build -->
  <ItemGroup>
    <FoldersToClean Include="$([System.IO.Directory]::GetDirectories(&quot;$(OutputPath)&quot;))" />
  </ItemGroup>
  <!-- Delete all of our localization folders and .pdb symbols. We only delete PDB files for Release builds. Debug builds we will leave them. -->
  <RemoveDir Directories="@(FoldersToClean)" />
  <Exec Command="del $(OutputPath)*.pdb" Condition=" '$(Configuration)'=='Release' " />
</Target>
在读了一点书之后,我明白了为什么它会这样做。App.config文件最终成为AppName.exe.config,以便在运行时使用。那很好;不过,我的转变来得很晚。编译完成后,AppName.exe.config文件包含我的基本App.config文件信息,并且不包含任何转换的设置。我假设这是由于转换是作为生成后步骤进行的,在使用原始App.config文件生成AppName.exe.config之后,转换App.config

string encryptedString = ConfigurationManager.AppSettings["SqlConnection"];
看起来没有任何东西阻止我改变

<TransformXml Source="App.config" 
              Transform="App.$(Configuration).config" 
              Destination="$(OutputPath)\App.config" />

以便在生成后替换AppName.exe.config文件

<TransformXml Source="App.config" 
              Transform="App.$(Configuration).config" 
              Destination="$(OutputPath)\AppName.exe.config" />

这有什么问题吗?在桌面应用程序中使用app.config和transforms时,没有多少帮助。我在网上读到的所有内容都是为了将内容转换为web配置文件。我认为这是安全的,或多或少是一样的。但是,我想通过将原始AppName.exe.config替换为转换后的App.config来确保我不会遗漏任何明显的副作用或问题。

安装此NuGet软件包,您将能够像创建web.config一样创建转换

还有其他几个Nuget软件包将像web.config一样转换app.config

前几天我用过这个,效果很好