How can I bundle the VC++ 2015 redistributable with my ClickOnce (.NET) application?
Asked Answered
C

1

8

I have a C# application running on the .NET Framework 4.5 deployed via Microsoft ClickOnce. I also am utilizing a small utility from a Microsoft SDK called DComPerm.exe which is a C++ application that I had to compile separately. My main application uses Process.Start() to access this executable.

When I first tried running this on a client machine, I got an error message stating that VCRUNTIME140.dll was missing when the application tried to call DComPerm.exe.

VCRUNTIME140.dll missing

This makes sense... since that program was compiled in C++ it needs the Visual C++ 2015 Redistributable package, which had not been installed on the client machine. I want to make this as painless as possible, so I was hoping I could bundle the VC++ 2015 Redist with my ClickOnce application. Under the project properties > Publish tab, there's a button for Prerequisites, which allows me to specify that the application should bundle the redistributable package.

Prerequisites on Publish tab

That sounds great in theory, but it doesn't work. Now when I try to install my ClickOnce application on the client machine, it doesn't work. The installation fails and points me to a log file, which contains the following relevant information:

'Visual C++ "14" Runtime Libraries (x86)' RunCheck result: Install Needed

Installation of components 'Visual C++ "14" Runtime Libraries (x86)' was accepted.

Copying files to temporary directory "C:\Users\Owner\AppData\Local\Temp\VSD3872.tmp\"

Downloading files to "C:\Users\Owner\AppData\Local\Temp\VSD3872.tmp\"

(8/4/2016 12:57:48 PM) Downloading 'vcredist_x86\vcredist_x86.exe' from 'http://go.microsoft.com/fwlink/?LinkID=800028&clcid=0x409' to 'C:\Users\Owner\AppData\Local\Temp\VSD3872.tmp\'

Download completed at 8/4/2016 12:57:49 PM

Downloading failed with HRESULT=-2146697208

And that message makes it pretty clear what the problem is: the link that it's trying to use to download the redist package is dead. Only... I'm not sure how I can tell it to find the correct link. I'm quite surprised that it can't find it automagically as that seems like a bug with Visual Studio. Some searching revealed that the correct link is actually this one, but that's not what ClickOnce is resolving. I also saw that by checking the box this was the corresponding XML update to my csproj file:

<BootstrapperPackage Include="Microsoft.Visual.C++.14.0.x86">
  <Visible>False</Visible>
  <ProductName>Visual C++ "14" Runtime Libraries %28x86%29</ProductName>
  <Install>true</Install>
</BootstrapperPackage>

Is there some XML tag I can use to specify the location explicitly? Or how else can I fix this? How can I bundle the redistributable without breaking my application?

Charleencharlemagne answered 4/8, 2016 at 19:23 Comment(3)
since that program was compiled in C++ it needs the Visual C++ 2015 Redistributable package Only if you link to the CRT DLLs. Why not link the CRT statically, instead (/MT, see CRT Library Features)?Imposing
@Imposing what you're saying here sounds promising but I don't really understand it. Are you saying that it's possible to essentially build the DLL into the executable itself, thereby negating the need for a separate redistributable?Charleencharlemagne
With the CRT statically linked the program won't depend on the VCRUNTIME DLLs. See for example How do I make a fully statically linked .exe with Visual Studio Express 2005? (it works the same for VS 2015).Imposing
A
6

I had pretty much the exact same problem. You asked how to specify the download location that ClickOnce resolves. In order to do that, open

C:\Program Files (x86)\Microsoft Visual Studio 14.0\SDK\Bootstrapper\Packages\vcredist_x86\en\package.xml

and edit the attribute with Name="https://go.microsoft.com/fwlink/..." to the correct URL. By the way, thanks for finding the correct download link, I hadn't been able to find it until seeing this post.

The VC++ Redis installed correctly on the client's computer after doing this.

Achromic answered 15/11, 2016 at 20:36 Comment(1)
Thanks for your help! And just for reference, here's the link to the x64 version.Charleencharlemagne

© 2022 - 2024 — McMap. All rights reserved.