我已经从 .NET4.0 DLL 创建了一个 NuGet 包,其中包含混合(托管和 native )代码。
native 代码打包在 .NET4.0 DLL 中,但依赖于 Visual C++ 2013 Redistributable
我正在尝试集思广益,用 NuGet 包打包 redist 和/或警告用户他们需要它,但我一无所获。
有人有什么想法吗?
最佳答案
实际上我自己解决了这个问题。虽然我找不到将 VCpp 运行时作为 NuGet 包的依赖项包含在内的解决方案,但我确实找到了一个警告用户需要 Visual C++ 2013 运行时的解决方案。
我在启动需要 VC++ 运行时的组件/库时静态运行此代码一次:
private static void AssertVcppDependencies()
{
var system32Path = Environment.GetFolderPath(Environment.SpecialFolder.SystemX86);
var system64Path = Environment.GetFolderPath(Environment.SpecialFolder.System);
string platform = Environment.Is64BitProcess ? "x64 and x86" : "x86";
bool success = File.Exists(Path.Combine(system32Path, MSVCP120DllName));
if (Environment.Is64BitProcess)
{
success &= File.Exists(Path.Combine(system64Path, MSVCP120DllName));
}
if (!success)
{
throw new InvalidOperationException("This Application Requires the Visual C++ 2013 " + platform +
" Runtime to be installed on this computer. Please download and install it from https://www.microsoft.com/en-GB/download/details.aspx?id=40784");
}
}
这应该提醒所有正在使用您的 NuGet 包的开发人员他们需要安装运行时。
关于c# - 依赖于 Visual C++ 2013 运行时的 NuGet 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33779063/