Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.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# 为什么Visual Studio为一个应用程序自动生成app.config,而不为另一个应用程序自动生成app.config?_C#_.net_Visual Studio - Fatal编程技术网

C# 为什么Visual Studio为一个应用程序自动生成app.config,而不为另一个应用程序自动生成app.config?

C# 为什么Visual Studio为一个应用程序自动生成app.config,而不为另一个应用程序自动生成app.config?,c#,.net,visual-studio,C#,.net,Visual Studio,我有3个项目的解决方案。一个是库,另外两个是控制台应用程序,它们都使用这个库 我在运行其中一个应用程序时遇到问题-对我的lib的调用调用System.Buffers.Binary.BinaryPrimitives生成程序集异常 我注意到他们的app.config文件不同: 应用程序A 应用程序B 所有这些附加的程序集都是我的库项目的依赖项,因此应该同时存在于这两个程序集中。我不知道为什么图书馆项目本身没有被引用 我从未接触过配置文件,因此它们是自动生成的,但不是等效的。为什么?我怎样才能

我有3个项目的解决方案。一个是库,另外两个是控制台应用程序,它们都使用这个库

我在运行其中一个应用程序时遇到问题-对我的lib的调用调用
System.Buffers.Binary.BinaryPrimitives
生成程序集异常

我注意到他们的app.config文件不同:

应用程序A

应用程序B

所有这些附加的程序集都是我的库项目的依赖项,因此应该同时存在于这两个程序集中。我不知道为什么图书馆项目本身没有被引用

我从未接触过配置文件,因此它们是自动生成的,但不是等效的。为什么?我怎样才能让VS再生


我能想到的唯一不同的方法是,当我开始在应用程序A中使用我的库时,VS建议添加一个参考,我接受了。在应用程序B中,我相信我手动添加了依赖项。

csproj文件中提到了引用,您可以通过右键单击项目、卸载、编辑来访问它。在那里它看起来像这样。您还可以在引用“文件夹”下管理项目引用

<ProjectReference Include="..\YourProject.csproj">
  <Project>{68836A56-12B9-4740-A78D-78F027336CBF}</Project>
  <Name>YourProject</Name>
</ProjectReference>

{68836A56-12B9-4740-A78D-78F027336CBF}
你的项目

大多数情况下,您不会出于参考目的编辑app.config。很快,app.config被用于运行时设置。

DLL被复制到bin文件夹中,但您是否检查了它的版本?一个控制台应用程序可以使用程序集绑定重定向,而另一个没有。我在意识到原因是app.config文件手动编辑app.config解决了问题后重新编写了这个问题,但让我担心:)另外,您没有提到您的项目有什么问题,因此,app.config可能与itI无关,我在app.csproj的两个文件中都找到了,看不出有什么区别。两者都引用了我的库项目。我如何强制它重建我的app.config文件?@Mr.Boy我仍然不确定你的问题与app.config有何关系,但你可以尝试这种方法。app.config中没有列出所需的程序集。手动添加它们可以修复issue@Mr.Boy我在回答中确实提到了这一点,“csproj文件中提到了参考资料”
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
    </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
</configuration>
<ProjectReference Include="..\YourProject.csproj">
  <Project>{68836A56-12B9-4740-A78D-78F027336CBF}</Project>
  <Name>YourProject</Name>
</ProjectReference>