C# how to compile programmatically while embedding .resx resource file - c#

This question might seem dumb, but I cannot quite understand the concept of C# compilation
I'm working on a C# project that contains two merged solutions
The first solution saves settings in the form of .resx resources files and the second solution reads them in said resx file located in roaming directory using Resource Writer and resource reader.
Now my problem is that I want the first solution to be able to compile the second solution's exe file while merging or embedding the resx file that contains the saved settings.
I'm not sure what should I do or what should I use or how to do this, this is my first time working on something that manually compiles the solution, I would've searched it on the internet but there are not a lot of tutorials concerning this specific matter, I felt lost and thus I'm seeking help from this forum in the hopes of finding a fix for this frustrating matter.

Related

Access to an embeded resource file doesn't work on Xamarin but on Windows App

I added an excel File (template.xlsx) to the project resources as an embedded resource. In my code I want to save that file to disk.
On Windows it works well with:
File.WriteAllBytes("test.xlsx", Properties.Resources.template);
But in my Xamarin.Forms project exactly the same line does not work because "Properties" is unknown in the current context.
I searched half a day in the net but all hints I got don't work either or confuse me even more. It seems I am missing an essential piece of base knowledge here. Could somebody tell me if I can easily access an embeded File in Xamarin similar like I do on Windows?
The difference I can see in the two test projects is:
In the project explorer of the windows project I can see Properties->Resources.resx. However, the template file is not located there but in Resources->template.xlsx
In the project explorer of the Xamarin project there is no Resources.resx in the Properties folder.
My file is again located under Resources->template.xlsx
You have to read that file in your code and then use it to write that file to file storage (application sandbox) of the platform. You can save files to that location, although you may not easily be able to access that file outside the scope of the app (say from another application).

user.config ignored assembly information and is located in default location

I have a C# excel add-in project which uses the User Settings.
The file is saved in a weird location, I guess that it is the default one. But as far as I understand, the location is derived from information taken from the AssemblyInfo.cs file.
In theory the path should be:
C:\Users\jeremy\AppData\Local<Profile Directory>\<Company Name>\<App Name>_<Evidence Type>_<Evidence Hash>\<Version>\user.config
But in my case, the user.config always ends up in:
C:\Users\jeremy\AppData\Local\Microsoft_Corporation\C__Users_jeremy_Path_u1gevrwm5dgrhpsynfqgtuhhmlxzqlm4\14.0.7132.5000\user.config
I double checked and information like Company Name or Version are well defined in my Assembly file. They are somehow ignored.
It causes me a lot of trouble because I have 2 applications which should be using their own user.config files, but because of this issue they write in the same file...
For info, I'm building my executables with Wix.
Do you have any hints to solve that?
I'm still not sure why I'm having this weird path, it might be because of the nature of the software which is a VSTO add-in.
In any case, I solved my issue by implementing a custom settings provider. It is a big overhead but I couldn't find any other solution.
Here's a very good tutorial:
http://www.geek-republic.com/2010/11/c-portable-settings-provider/

Proper procedure to import existing RESX files into a C#/WPF project

I have my auto generated Resource.resx file set up with keys and strings. I also have three other resx files for German, French and Spanish given to me from translators. I'm not able to get the localization functioning and I suspect that the resx files aren't being called correctly. I added them to the project by dragging them into the solution explorer under "Properties". I have a nagging suspicion that just dragging them in isn't creating the proper connections behind the scene.
Now It's totally possible my issue lies somewhere else. If anyone can tell me whether it's ok to add resource files this way or if not, what the correct way is, it would save me tons of time spent chasing my tail. Thanks!
Resx files in Visual Studio include a special tool which is run at build time and translates them into embedded resources. Right-click your original VS-created resx file and click Properties. You should see Build Tool or something similar. Also note the resource type (Embedded, etc.). Make sure that you match these settings for your manually added files.
Once this is set up, you will need to use the CurrentUICulture property to tell .NET to pick up the appropriate resources. You can choose to change the culture/language at install-time or run-time. Here is a comprehensive tutorial which describes the various options available to you:
WPF Localization Using RESX Files
That said, as a best practice, translated Resx files are generally deployed as satellite assemblies. The main application DLL/EXE contains only the language neutral resources file. Other resource files are compiled into separate assemblies and deployed side-by-side with specific naming conventions. This allows you to dynamically add translations, localizations, etc. even after the application is deployed. Here's an introduction: Packaging and Deploying Resources in Desktop Apps

How to add source file (.cs) to resources (.resx) in a pre-build event?

Is it simple or even possible?
Why: Following my other question and using this approach, now I would like to simply embed the source file to the resources so I can copy it to the temp folder while the application is running - and keep the application as a single file.
I assume using a pre-build event is the best way to do this. If so, how would it be done?
EDIT: I'm asking about adding it before building because I also assume it won't be automatically updated if I add it manually once and then change the code after.
I recently went through this same issue when developing an examples suite for a .NET control which had to display its own example source code in the application.
The approach I ended up with was as follows.
I created a batch script (run in pre-build) to copy all the code files under /Examples/* to another folder in the solution Resources/ExamplesSrc/*
I then included all these files under Resources/ExamplesSrc/* in the csproj and saved it.
The next step was I set all the files under Resources/ExamplesSrc/* as embedded resource and committed the change to SVN. I did not commit the examples (generated) to SVN, just the modified csproj and batch file.
The effect when developers checked out was that they had (!) icons on all the resources (they were not on disk, but the csproj was looking for them), however as soon as they built the generated files appeared and all was well. This approach also worked with a build server (Team city) and the examples suite can now load and browse its own code via embedded resources.
One caveat you should be aware of. There is a quirk (by design apparently) in VS2010. If an embedded resource has ".cs" in it (i.e. any code file!) it cannot be loaded from the assembly using Assembly.GetManifestResourceStream(). To work around this all source files were renamed in the batch copy step from *.Xaml.cs to *.Xaml.c.txt, from *.cs to *.c.txt
Hope this helps!
Turns out I don't need to (re)add the source file each time I build the solution!
When I add it manually once it becomes a "Text" file on resources - and I can easily access it as a string using Properties.Resources.SourceCode (having the file named "SourceCode.cs"). And yes, it is updated automatically since the resource property "Persistence": the file is linked at compile time.

.resx File Size Issue

I am working in Visual Studio 2010, on a fairly beefy machine. I have a solution with a few different projects under it like so
Solution
Activations
DatabaseManager
Library
VideoResources
WindowsNewUI <--- start up project
In video Resources I have one .resx file in which I have placed about 700mb of compressed videos. When I build this project by itself, the build succeeds. Then I hit f5 to run my new UI and I am given this error.
Error 1 Unexpected error writing metadata to file VideoResources.dll -- 'Not enough storage is available to complete this operation.
I have done some digging and it seems to be a ram issue. I have tried the /3gb fix by editing the .ini file, but this does not solve the problem.
My question is what the heck am I doing wrong here, I know that 700mb is a lot of video, but there is no reason that that specif project should build, but then fail the rest of my project, is something else going on here? Does the access modifier of that projects resource file mater? How can I resolve this issue?
Also if I place about half of my video files in the .resx then everything works just fine.
My suggestion would be to not store the video in any type of embedded resource. Thats going to cause your app to us a ton of memory while it is running. I would suggest that you instead just leave the files on disk and load them from there. This would also fix your problem.
The resource file infrastructure is probably not designed to scale to these file sizes. Remember that every operation in a resx file happens in memory, and you're using a garbage-collected language.
Why not just store the video(s) in the filesystem and read them as needed?

Categories

Resources