我已经从包含混合代码(托管和本机代码)的.NET4.0 DLL创建了一个NuGet软件包。
本机代码被打包在.NET4.0 DLL中,但是需要Visual C++ 2013 Redistributable的依赖项。
我正在尝试构思一些方法来将redist与NuGet软件包一起打包或者警告用户他们需要它,但我却不知道如何做。
有人有什么想法吗?
我已经从包含混合代码(托管和本机代码)的.NET4.0 DLL创建了一个NuGet软件包。
本机代码被打包在.NET4.0 DLL中,但是需要Visual C++ 2013 Redistributable的依赖项。
我正在尝试构思一些方法来将redist与NuGet软件包一起打包或者警告用户他们需要它,但我却不知道如何做。
有人有什么想法吗?
我其实自己解决了这个问题。虽然我找不到一种将VCpp Runtime作为NuGet包的依赖项的解决方案,但我找到了一种解决方案,可以提醒用户需要Visual C++ 2013 Runtime。
我在组件/库需要VC++ Runtime的启动时静态地运行此代码:
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包的开发人员需要安装运行时。
bool is64bit = IntPtr.Size == 8
来检查当前应用程序的平台,并且只测试一个 dll。 - Patrick Stalph