Open bh-ubunye opened 2 months ago
Your resource file should be embedded in the assembly at compile time. Then you can access it at runtime as in any WPF application.
Have a look at this thread, it seems to be related: https://github.com/oleg-shilo/wixsharp/issues/1499
Ya, we thought the same, but our MSI installer is unable to access other language resource files (ex., German translation) other than English during runtime.
Whether we needed to include all other language resource files in MSI code?
As I mentioned in that issue I referenced, you have two options:
Binary
). Then at runtime extract the data from the Binary
table and either save it to a temp file (and then load with res manager from the file) or load with res manager from the bytes you just read from the msi table.Hi Oleg,
Do you have any samples of load binary table into res manager?
All the required bits are sprinkled around the sample projects (e.g. MultiLanguageUI project, ProgressDialog.cs ) but since it is a generic .NET technique, I will summarize it:
project.AddBinary(new Binary(new Id("de_dlll"), "de-DE.dll"));
project.UIInitialized += (SetupEventArgs e) =>
{
byte[] de_data = e.Session.ReadBinary("de_dll");
Assembly externalAssembly = Assembly.Load(bytes);
Stream resourceStream = externalAssembly.GetManifestResourceStream("<your resource name>");
using (StreamReader reader = new StreamReader(resourceStream))
{
string content = reader.ReadToEnd();
// Use the content read from the resource
}
};
And if you want to dynamically substitute WPF resource dictionaries at runtime it is also possible (I did it long time ago 😄) but you will nee you will search for the solution from WPF sources.
Hi Oleg,
We created our installer UI from the WPF project and embedded it in the MSI project; therefore, we were unable to access the session binary to extract the other language resources, and EmbeddedUI msi was unable to execute the UIInitialized.
Does it have any ways to let us access the binary file we bind to MSI in the WPF project?
I am not sure I follow.
Any embedded UI that is packed with msi is loaded at runtime by msi and an active session object is passed to it. Always.
If you are using WixSharp-provided UI then the session is channeled through WixSharp events like UIInitialized
.
If you are using your own raw UI then it has to implement:
bool Initialize(Session session, string resourcePath, ref InstallUIOptions internalUILevel);
Meaning that you always have access to the session. And then you can always read binary.
So I do not really understand we were unable to access the session binary
.
I believe I misrepresented our problem, we were able to acccess the session in our raw UI project. Our problem was that we couldn't read the binary file that was associated to the session in our own raw user interface, even though we could access the session.
Do we need to add the "Wixsharp" reference to our UI project in order to utilize the reading function, or is there another way we may be able to access the binary file?
Great. We are now progressing.
If you have access to the session then it should be no problem reading the msi tables.
Our problem was that we couldn't read the binary file that was associated to the session...
The description above is not explicit but it makes me think that you are talking about a runtime exception.
However Do we need to add the "Wixsharp" reference?
makes me think that you do not reference WixSharp currently, what makes this code break the compilation:
byte[] de_data = e.Session.ReadBinary("de_dll"); // ReadBinary is implemented in WixSharp.dll
And yet you did not indicate what type of problem it is (e.g. compile time vs runtime).
I am guessing that it is in fact compile time so I suggest you add the reference and use the code snippet I provided earlier.
Hi Teams,
We are developing an MSI installer using an embedded WPF UI. We would like to localize the string display inside the controls of the installer's WPF.
We are using the resources file specific for the language. Our resources files generated during pipeline creation.
During the MSI installer's run time, how can I get to the localized resources?