Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NuGet package with a dependency on Visual C++ 2013 Runtime

I have created a NuGet package from .NET4.0 DLLs which include mixed (Managed and native) code.

The Native code is packaged up inside the .NET4.0 DLL but has a dependency on the Visual C++ 2013 Redistributable

I'm trying to brainstorm ways to either package the redist with the NuGet package and/or warn the user that they need it, but I'm drawing a blank.

Anyone got any ideas?

like image 823
Dr. Andrew Burnett-Thompson Avatar asked Nov 18 '15 11:11

Dr. Andrew Burnett-Thompson


Video Answer


1 Answers

I actually kind'of solved this myself. While I couldn't find a solution to include the VCpp Runtime as a dependency to a NuGet package, I did find a solution to warn the user that the Visual C++ 2013 Runtime was needed.

I run this code once, statically, at startup of the component/library that requires the 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");
        }
    }

This should alert any developers that are consuming your NuGet package that they need to install the runtime.

like image 87
Dr. Andrew Burnett-Thompson Avatar answered Oct 13 '22 02:10

Dr. Andrew Burnett-Thompson