Recommand · October 14, 2021 0

How to Reference A Binary File in a C# ClickOnce Install Application

I’m currently using C# to build an app using WebView2, however, I need to make it accessible for those who are currently not on Edge. I decided to use a fixed version runtime, as documented here.
I’m going to use "EnsureCoreWebView2Async" to specify my environment.

My question is how do I reference the binary files needed in the “browserExecutableFolder” parameter in “CoreWebView2Environment.CreateAsync” if I’m going to package the project using ClickOnce? I won’t know where the user will install the file, so I don’t know what directory to reference. Could I just reference the file based on the package directory, like below:


…or is there another file reference syntax I would need to use?

Sorry if this seems like a beginner’s question, but I just recently started learning C#/.NET and I’m still trying to get the hang of programming altogether. 🙂

You can package the binary file in the click once installer. When this gets extracted the binary file will be in the same (i recon) directory as the application installed.
Which click once installer will be used for installing the application?

Once you know where the binary file gets placed on installation and if it is in the same folder as the installed application, you can use the following code for getting to that path.

var exePath = System.Reflection.Assembly.GetEntryAssembly().Location;

Documentation for above

When using it with Path.Combine(exepath, "nameofbinaryfile");

You can get a reference to the binary file.