如果添加了 NuGet 包,为什么 Visual Studio 会更改 app.config?

问题描述 投票:0回答:1

在将故意的 NuGet 包添加到 .NET Framework 项目(在我的例子中是 4.8 版)之后,通常有两种类型的文件发生变化:packages.config 和 csproj 文件。 但有时 app.config 也会发生变化,如果还没有 app.config 文件,Visual Studio 会添加一个。看这里的例子:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Extensions.Configuration.Binder" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-7.0.0.4" newVersion="7.0.0.4" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

为什么?为什么 package.json 和 csproj 不够?我是否必须将 app.config 部署到生产机器上?通常,如果我的应用程序需要配置选项,我只会部署一个 app.config 文件。如果我不想“污染”目标系统,我可以省略生成的 app.config 文件,还是会在某个时候出现运行时错误?

c# .net visual-studio nuget nuget-package
1个回答
0
投票

这是因为存在使用相同dll但版本不同的依赖项。 app.config 中的那一行告诉应用程序继续并获取 dll 的最高版本。因此这是必需的。

见: https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/redirect-assembly-versions

© www.soinside.com 2019 - 2024. All rights reserved.