.NET Standard:依赖项未复制到输出目录
.NET Standard: dependency not copied to output directory
我正在将 .NET Framework 库转换为 .NET Standard 2.0,因为我需要在旧的 .NET Framework 项目和现代的 .NET 5 项目中使用它
在原始库中,我使用 ProtectedData
class,它是 .NET Framework 的一部分(来自 System.Security.Cryptography
程序集)。
这不是基础 .NET Standard 库的一部分,因此为了使其正常工作,我添加了适当的 NugetPackage,System.Security.Cryptography.ProtectedData
。
有了这个,项目编译正确,但是当我尝试 运行 它时,我得到以下错误:
System.IO.FileNotFoundException: 'Could not load file or assembly
'System.Security.Cryptography.ProtectedData, Version=6.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its
dependencies. The system cannot find the file specified.'
所以我查看了编译输出目录,我发现没有 System.Security.Cryptography.ProtectedData.DLL
文件的踪迹,这就像编译系统没有将依赖项复制到输出目录。我该如何解决这个问题?
在另一个论坛上找到了这个答案,它似乎有效。
我补充了:
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
到 .csproj 文件,现在正在正确复制依赖项。
仍然想要解释为什么需要这样做,因为我以前从未为其他项目这样做过...
我正在将 .NET Framework 库转换为 .NET Standard 2.0,因为我需要在旧的 .NET Framework 项目和现代的 .NET 5 项目中使用它
在原始库中,我使用 ProtectedData
class,它是 .NET Framework 的一部分(来自 System.Security.Cryptography
程序集)。
这不是基础 .NET Standard 库的一部分,因此为了使其正常工作,我添加了适当的 NugetPackage,System.Security.Cryptography.ProtectedData
。
有了这个,项目编译正确,但是当我尝试 运行 它时,我得到以下错误:
System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Security.Cryptography.ProtectedData, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'
所以我查看了编译输出目录,我发现没有 System.Security.Cryptography.ProtectedData.DLL
文件的踪迹,这就像编译系统没有将依赖项复制到输出目录。我该如何解决这个问题?
在另一个论坛上找到了这个答案,它似乎有效。
我补充了:
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
到 .csproj 文件,现在正在正确复制依赖项。
仍然想要解释为什么需要这样做,因为我以前从未为其他项目这样做过...