In my application i have a bunch of string definitions.
I have put them as within the resources of visual studio with the idea so that it would save as an xml .resx file. The reason for this, is that after deployment i would be able to change some string definitions when i need to for some reason.
So, i have set the resources properties build action to be "XamlAppDef" and the Custom tool is automatically set to "PublicResXFileCodeGenerator" by visual studio.
Furthermore i linked system.xaml in my project references.
Although the .resx file is automatically generated, i now get an error during compile:
The XAML MSBuild task only processes files that contain an '{http://schemas.microsoft.com/winfx/2006/xaml}Class' directive. Please refer to documentation for usage of ‘{http://schemas.microsoft.com/winfx/2006/xaml}Class’
i tried figuring out how to fix this, but i cant really seem to figure it out. Any thoughts ?
The XamlAppDef is exactly only for XAML, not RESX resources. Use the Content build action instead.
Related
While using Java in Eclipse IDE, one can add a folder to the "Build Path" using the "Add Class Folder" option in the "Libraries" tab, which allows the resources in that folder to get compiled inside the application's jar file, rather than outside or not at all.
.
With this, one can get the resources inside the folder as a URL via the Class.getResource(String name)method. I am already informed about C#'s equivalent: Assembly.GetManifestResourceStream(string name) or Assembly.GetManifestResourceInfo(string resourceName) methods, but I am not aware of C#'s "Build Path" equivalence in Visual Studio (I am using 2019, if you wished to know). Could somebody please explain how I would accomplish Java's build path resource folder in C#?
(Note that I am looking to create a resource folder where anything put inside the folder would be considered an application resource. I am not looking for a way to add one or more resource files individually.)
Any replies would be greatly appreciated! :)
After a little research, I had found a solution for this problem. There are in fact two possible solutions to this issue.
.NET Core Solution
The first involves editing the .csproj file of your C# project. This solution is only available in .Net Core.
You can add this code snippet to your file and change the {PATH_TO_RESOUCE_FOLDER_HERE} folder to your desired folder.
<ItemGroup>
<EmbeddedResource Include="{PATH_TO_RESOUCE_FOLDER_HERE}\**" />
</ItemGroup>
Now any item placed in that folder will be considered an embedded resource Assembly.GetManifestResourceStream(string name) method.
Regular .NET Solution
The second method involves using a .resx file to encapsulate all of your resources
In Visual Studio 2019, you can create a .resx file by right clicking on the location in your project where you wish to add the file to, and navigating to Add > New Item (you may also press Ctrl+Shift+A). You can now navigate to the item that quotes "Resources File" and select it. You can now use this GUI to insert your resources (for a deeper explanation, click on this or this link. For use cases, see this MSDN).
The "Resources File" option
Note that this solution will also work in .NET Core.
I hope this answer helped you as much as it did me! :)
You just create a folder and name it as you like it, say 'Resources'. Add any file you want in there to be treated as a resource by your application.
Then navigate to the properties of every resource file (you can press F4) and in the menu you can choose what you want the compiler do with that file (Compile Action is the option name if I remember well). There you select the type as a resource, the namespace (your Build Path), and whether you like the file to be copied every time you compile your application, and so on.
I'm forced to work with a tool that generates it's own solution files (.sln). The tool is building the solution based on whatever files that end with .cs. The problem is that you can't change files properties as the solution gets regenerated each time you rebuild. This means that you can't set files to always copy in Visual Studio, as it will be reset the next rebuild.
After looking online for a while I was wondering, is there a way to reference files as always copy with C# tags?
For example... Reference.cs
[assembly: AlwaysCopyToOutputDirectory("path/to/my/file.xml")]
Is there a tag like this that I can include in my code in order to change the file properties automatically?
I had a Properties file called RecentFileList within my Visual Studio 2012 project and I removed it. I believe it was a .settings file. Now when I run my setup project, it is trying to copy files that it shouldn't care about and it's bombing out as a result. I get 3 errors (-1007 -6271 and -6103), all related to the same missing file.
-6103: Could not find file "C:\Users\Charles\Documents\Visual Studio 2012\Projects\RallyCourses\RallyCourseDesigner\bin\Debug\Properties\RecentFileList.Designer.cs
What file do I need to edit to get rid of the reference to this file? I tried searching for RecentFileList.Designer.cs, but can't find it.
The offending files in my situation were trying to be installed by the installer, but I had removed them from the main project. Within the SetUp project, there is a section Specify Application Data -> Files. I found the files in the Properties section there, removed them, and things are working now...
I'm getting an error that reads:
The custom tool 'PublicResXFileCodeGenerator' failed while processing the file 'Properties\Resources.resx'
I haven't the slightest clue how to fix it.
If any of you know what's going on here, I could use your help.
Whenever a .resx file is compiled, Visual Studio runs it through the PublicResXFileCodeGenerator (or InternalResXFileCodeGenerator, if it's visibility is internal) to generate the actual strongly-typed properties that you use in your code.
If there is something wrong with the XML in the file, malformed or corrupted perhaps, then the process might fail. Can you open the file in the resource view?
Follow these instructions:
Copy the contents of Resources.resx to a new resource file.
Delete Resources.resx from the project.
Unload the project
Reload the project.
That should get rid of the compiler warning.
try this ..
Open your fileName.resx file in windows explorer and right click - Properties
maybe you will find "This file came from another computer and might be blocked to help protect this computer."
Check [Unblock] checkbox and apply then try to build your solution again.
I am just learning about app.config in respect of creating custom sections. I have that part working, it compiles and gets the information out as required but I get warnings about it could not find the schema information.
I have done a bit of googling and could not find a simple explanation of this situation.
The approach (that seems to make sense to me at the moment) would be to have a schema file for each section within that project. I understand how to create a schema file, but do not know how I would like this into the project.
Also when it is compiled and deployed to another machine I presume that schema file would need to be copied across as well.
Thanks for any and all help
Jon
Try linking the app.config file to the corresponding schema (ussually you can find it on C:\Program Files\Microsoft Visual Studio 8\xml\Schemas\DotNetConfig.xsd) ,to do so just open the app.config file in visual studio, open the properties window (F4) and put the path above to schemas.
Pablo.