If I include a .bin.gz file in a DLL as an embedded resource, it doesn't show up in the Assembly.GetManifestResourceNames() list, and cannot be loaded with Assembly.GetManifestResourceStream(). If I rename the same file to anything else, it does show up.
The .bin.gz file shows up in .csproj. I'm building a .NET Core 2.2 class library.
What's going on? Is there some kind of filter by file type that prevents certain types from being embedded?
EDIT: On further inspection. It appears that the .bin.gz resources are placed in a different .dll named [AssemblyName].resources.dll, which is placed in a "bin" folder next to the [AssemblyName].dll. Why is this and why does this not happen with other files?
Related
my visual studio project has some includes (i use the .net framework 4.6.1).
So I wanted to do a loader in .net 2.0 for unpacking the needed files without admin rights into a user folder with the EXE together.
My idea was to add them as type "FILE" resource into the "loader" project and then extract them as a file again in the user directory together with the .net 4.6.1 EXE. As soon I add one of the files to my NET 2.0 loader project as resource in the designer, the whole project is broken and spits out errors, which I do not understand.
How I can add a complex file as a resource in my project (DLL / EXE)? Simple TEXT-Files work so far. (The extracting routine works also). I get the error right after adding a binary dependency file (DLL) like "System.Data.dll". It says after adding the resource that I have a wrong reference or something alike. The project becomes immediately unusable after it with that error persisting. If I delete the file out of the resource again, the error persists. I have to start all over again with the project.
Any ideas?
I'm writing some integration tests for some SQL scripts that live in a folder separate from the project. Since the setup of the machine I'm writing on the tests on differs from the machine they will be run on, I would like to include them as resource files rather than hard coding any paths. However the default behavior for adding an existing file as a resource file simply copies the file, which is not what I want in case any of the SQL scripts get updated.
Does anyone know the best way to get the resource file to actually reference the SQL scripts that are in a folder separate from the project, or to somehow copy them into the assembly at compile time so I don't have to load them via absolute/relative paths?
Edit: For clarity, I'm trying to get the resource file to act as a symlink to the original file at compile time. Adding an existing file to a resource in file in Visual Studio simply makes a copy of the file, which means any changes to the original are not propagated to the resource file.
After asking on IRC, someone guided me to what I was looking for. You are able to add an existing file to a project as a link (there is an arrow on the Add box when in the file dialog), and set it's Build Action property to Embedded Resource
https://support.microsoft.com/en-us/kb/306234
Daniel posted a link on how to actually read an embedded resource:
How to read embedded resource text file
I have created a C# WinForms application. It has some additional files that it uses, such as help files and some external data files. I want to put these files in folders under the Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) path so that the application can find and read them.
This path doesn't get created until the application is installed right? So where do I put these files in my VS2010 project, or how do I tell my project that these files exist so that when I am running (debugging) the application from VS it will find the files.
Thanks
EDIT: I did think about adding the files as resource files, but unfortunately some files may get added after the project is built and deployed. Therefore we decided to make the program search and find the data files (and associated help files) at a specific location and load them if they exist.
Thing is that your application should not need to use 'Environment.SpecialFolder.ProgramFiles'. It "should" be location agnostic. The quick answer to your question is "from the folder that the application was launched from". The real answer is how you reference these files.
Your help files and data files need to be deployed to folder with a known relationship to the application. That is, the same folder or a child folder. Consider making the file resources.
Now if the files are user configurable or run time writable then they should not be in the program files area but be in the application data area. If so, then there is your path!
Hope this helps.
You should add these files to the main (exe) project inside your solution.
(Right click on Project Name, Select Add Existing Item)
Then set its property Copy to Output Directory = Always
(not sure of the translation because I use a localized version of VS)
Of course, it should be noted that, when you deploy your files in the Environment.SpecialFolder.ProgramFiles, you could not be able to write to them (Windows7, Vista) for security reasons.
Add the files as resources in your project. Take a look at this MSDN article. You can add resources to a project by right-clicking the Properties node under your project in Solution Explorer, clicking Open, and then clicking the Add Resource button on the Resources page in Project Designer.
You can add resources to your project either as linked resources, which are external files, or as embedded resources, which are embedded directly into the .resx file.
When you add a linked resource, the .resx file that stores your project resource information includes only a relative path to the resource file on disk. If you add images, videos, or other complex files as linked resources, you can edit them using a default editor that you associate with that file type in the Resource Designer.
When you add an embedded resource, the data is stored directly in the project's resource (.resx) file. Strings can only be stored as embedded resources.
I have a C# project that has multiple folders: Folder1, Folder2.
I added a shortcut in 'Folder1' to an xml file that is already in 'Folder2'. In this case when I compile the project the xml file will I have two copies in the assembly?
You were not clear with your description - did you reference the file with a shortcut, or did you add it to Folder1 by using the VS Solution Explorer and adding an existing item as a link?
The two methods are quite different. If you simply went into the filesystem and added a shortcut, then that is not automatically part of the project unless you specifically add it. And if you did add it, then it obviously can't be compiled, the best you could do is just have it set to No Compile and copy to the output directory.
If you added the file to folder one via the VS solution explorer and added it as a link, then it will be part of the project, and will be included twice, but it will be placed in Folder1 under the bin/debug or bin/release folder upon building. There will be no clash because they are in different folders, and they are not compiled, simply copied to the folder structure under the output directory.
Edit: and it won't be part of the assembly unless you set it to be a Resource or Embedded Resource. If you do that then yes, it will be in the assembly, but under two different resource paths.
In the Properties(context menu) of the selected file in the Solution Explorer change Build Action property to No Compile.
I have an image that is used in some PDF files that my C# application generates. I know how to reference the image file when it is located in my workspace, but when I compile the program, I don't see the image anywhere in the compiled directory.
Can someone tell me what happened to that file, or do I have to manually package the file along with my program when I send the program to the users? I added the image to the workspace by drag-drop to the resource directory of one of my namespaces.
Check the file's properties in Visual Studio. Have you set the CopyToOutputDirectory property to something besides Do not copy?
Hmm... I'm not sure about the whole drag-drop business, but if it's all working the resource will have been embedded into your assembly.
I suggest you have a look with Reflector - you can see the resources embedded within assemblies using that.
Have a look at the build properties for the item in Solution Explorer - in particular, if the build action is Embedded Resource then it will indeed be built into the assembly.