I recently needed to deploy a WPF application with ClickOnce and have the deployment include an ActiveX DLL. I couldn’t simply add a reference to the DLL in my solution. When I tried I Visual Studio said:
Please make sure that the file is accessible, and that it is a valid assembly or COM component.
Since I couldn’t add it as a reference – it wouldn’t show up in my “Application Files” list (Publish tab of project properties). If it isn’t in the Application Files list then we are unable to include it in the ClickOnce publish.
To get around this issue there is a simple trick you can do to push your ActiveX DLL (or any file type ) into a ClickOnce publish. Here are the steps:
- Rename your file to include a .txt extension. It should look something like “myassembly.dll.txt” or [name].[extension].txt’
- Add the renamed file to your solution.
- In Solution Explorer right-click the file, select properties, and change the Build Action to “Content”
- Now go back to Application Files on the Publish tab of the project properties. You should see your file in the list. If they aren’t already set – change the drop downs so that the values are as follows:
- Publish Status – Include (Auto)
- Download Group - (Required)
- Hash - (Include)
After those step are complete, you have a small amount of coding to do. We’ll need to rename your file at runtime in order for the file to be usable. To do that we’ll need a bit of code from my last post.
if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
{
if (System.Deployment.Application.ApplicationDeployment.CurrentDeployment.IsFirstRun)
{
//sneak the dll into the deployment by renaming it
if (File.Exists("myfile.dll.txt") && !File.Exists("myfile.dll"))
{
//rename to dll so it is accessible
File.Copy("myfile.dll.txt", "myfile.dll");
}
}
}
The code above basically checks to see if it is a ClickOnce deployment and if it is the first time the application has been ran on the current machine, and if so, renames the .txt file you publish with it’s real name so it can now be used as originally intended.
Using the method outlined in the post, you should be able to easily publish any file type with your ClickOnce deployed application.
Enjoy!
.NET, WPF
wpf, clickonce