Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.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
C# 应用程序机密文件内容未包含在项目输出中_C#_Visual Studio_Visual Studio 2017 - Fatal编程技术网

C# 应用程序机密文件内容未包含在项目输出中

C# 应用程序机密文件内容未包含在项目输出中,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

我有一个包含许多项目的解决方案。在启动项目中,my
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>