C# 应用程序机密文件内容未包含在项目输出中
我有一个包含许多项目的解决方案。在启动项目中,myC# 应用程序机密文件内容未包含在项目输出中,c#,visual-studio,visual-studio-2017,C#,Visual Studio,Visual Studio 2017,我有一个包含许多项目的解决方案。在启动项目中,myApp.config引用了appSettings元素中的另一个文件。但是,当我在编译后打开编译的StartUpProject.exe.config文件时,它不包含AppSettings.config中的数据 App.config <?xml version="1.0" encoding="utf-8"> <configuration> <appSettings file="AppSecrets.config"&g
App.config
引用了appSettings
元素中的另一个文件。但是,当我在编译后打开编译的StartUpProject.exe.config
文件时,它不包含AppSettings.config
中的数据
App.config
<?xml version="1.0" encoding="utf-8">
<configuration>
<appSettings file="AppSecrets.config">
<add key="config variable" value="this key works"/>
</appSettings>
</configuration>
<appSettings>
<add key="secret config variable" value="this key does not work"/>
</appSettings>
我希望在构建的StartupProject.exe.config
文件中看到如下内容
<?xml version="1.0" encofing="utf-8">
<configuration>
<appSettings>
<add key="config variable" value="this key works"/>
<add key="secret config variable" value="this key does not work"/>
</appSettings>
</configuration>
我做错什么了吗?我的期望错了吗?是否需要将
AppSecrets.config
文件包含在项目输出中才能正常工作?我通过在项目输出中包含AppSecrets.config
解决了这个问题。不确定这是否是正确的方法,但它起了作用
我将文件“build action”设置为
Content
,将“copy to output directory”设置为copy if Newer
原因是,在file=path
中,路径是相对于可执行文件的,而不是相对于App.config文件的。所以它需要和EXE文件放在同一个文件夹中。您需要在生成时将其复制到输出目录,就像您所做的那样。尝试configSource=
而不是file=
刚才尝试了一下,同样的问题
<?xml version="1.0" encofing="utf-8">
<configuration>
<appSettings>
<add key="config variable" value="this key works"/>
<add key="secret config variable" value="this key does not work"/>
</appSettings>
</configuration>