Where to put resource file in web application - c#

I am using resource file to manage strings to show in UI. I have requirement to show enum values to UI.
Definitely I can do it with [Display] attribute to achieve this. However i have common project for POCOs where i create Enums as well and to use display attribute, i would require to take resource project's reference in that POCOs project.
This causes resource file gets copied in every other projects who uses that POCOs including WCFs where it is not requried.
Any suggestion to achieve Displaying ENUM from Resource file but not let other projects to build Resource file DLL?

Related

Changing Application Settings in .net project on build or publish

I have an older asp.net solution consisting of several projects. The data access layer is contained in a separate class library project while the frontend is in another project.
The data access project is using Application Settings (https://msdn.microsoft.com/en-us/library/a65txexh.aspx) for several settings, among others 3 connection strings. I have a /Properties/Settings.settings file which - when changed - results in an updated /app.config file.
My problem is that I haven't found any way to automatically change these settings when building and publishing the solution.
I know about web.config transformations (https://msdn.microsoft.com/en-us/library/dd465318(v=vs.100).aspx) and that Visual Studio offers the ability to create a so called "Config Transform". But as far as I know a class library doesn't have a web.config file and this menu option is not available for neither the Settings.settings file nor the app.config file.
Is there a way to automatically change the settings.settings file/app.config or is there a completely different best practise to provide connections strings to a class library?
EDIT: I should add to the above that the Data Access class library is using Datasets.

How to read the properties of an .resx file in a Web site project of asp. Net from a dll assembly

I'm new in .Net and working with two projects in c# a class library project(dll) and a website asp project.
I need to read some properties from a file .resx that is in the App_GlobalResources folder of the website.
Is there a way to read these properties in the .resx website file from a dll assembly more specifically in the method onPreRender??
Thanks for you attention
It sounds to me that you are having some problems with structuring and dependencies in your solution. (Trying to reference the website from a DLL)
Generally speaking, your DLL should not need to access the resources of the website on its own - you should only pass them in through as parameters when calling various methods that are contained in the DLL itself.
Have you thought about migrating the resource file to the DLL?
That would allow both DLL and the website to read from it.
Another option would be to migrate the setting you need to the .config file which you can read by using the ConfigurationManager class ( MSND Link )
You should be able to use it like this, even from your Code repository project:
string settingValue = ConfigurationManager.AppSettings["YouSettingNameHere"].ToString();
However, if you really want to keep your current solution structure you can follow the answer that Pavel Chuchuva gave on a similar question here.

Using XNA Content Pipeline in a C# Form

I'm trying to create a game editor using a C# form, and I've run into a problem when it comes to deserializing; I can't use the content pipeline in a forms application as I don't even have the option to add any content reference to the project. How can I use the content pipeline with my form app? Is there another way to load and deserialize my XML content?
Manually edit the .csproj file and add the following in the first PropertyGroup section which contains the assembly name, project guid etc.
<ProjectTypeGuids>{6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
You'll probably need to also add
<XnaFrameworkVersion>v4.0</XnaFrameworkVersion>
<XnaPlatform>Windows</XnaPlatform>
Reload the project in VS, and you should be able to add content references to it.
The two GUIDs specified there are for Windows and XNA (Windows). Here is a list of some common project type guids (although slightly dated) if you need to retarget the project at all.
Take a look at the Winforms Series 2: Content Loading AppHub sample.
Basically you load and call appropriate microsoft.xna.framework.content classes to read your compiled xnb files.
You'd use classes in the namespaces within microsoft.xna.framework.content.pipeline to create the xnb files (which is what the content project would do for you).
See here for an overview of the content pipeline: What is the Content Pipeline?
Is there another way to load and deserialize my XML content?
Yes, use any .net method of serialising you want, maybe XDocument.

When should I use Satellite Assemblies when it comes to localization? And When should I use Resources Files(.resx)?

I'm creating a windows appplication in which I wanna do some localization. That application will also use a DLL that might use a different language(CultureInfo) than the main application. Which one of those two localization concepts applies best to my case?
I don't quite think you understand .Net's localization model.
Actually, when you add resx file to your project in Visual Studio and set language (change from Default to something else), not only it will automatically create language copy of your Default (invariant) resource file, but will also create Resource Managers to load data from Satellite Assemblies behind the scenes. Go ahead and try it by yourself. You should observe some language-based subdirectories with satellite assemblies in your output directory.
Therefore your question quite does not make sense.

What's the difference between a Resource and an Embedded Resource in a C# application?

When should I use one or the other?
I'd like all of the files I use in my app (images, sound, xml file, etc.) to be inside of the .exe file so I don't deploy with a bunch of folders and files.
Thanks for the info.
“Resource” and “Content” build actions are to access the WPF resources using the Uris. However “Embedded Resource” is for prior technologies. However both options embed the resource in assembly but “Resource” option to be used for WPF.
MSDN provides full explanation here.
A WPF resource (build action = Resource) leverages embedded resources as supported by the core .NET framework, but adds support for accessing the embedded resource via a pack URI. From MSDN:
WPF resource files are not the same as
the embedded or linked type of
resources that can be configured using
the core .NET Framework support for
assembly resources. While WPF resource
files do leverage the core .NET
Framework embedded resource support,
the ability to access WPF resource
files using pack URIs is easier than
using namespaces.
As reported by MSDN,
Embedded resources are the best choice
if you have to share application
resource (.resx) files between
multiple projects. For example, if you
have a common resource file that
contains your company's logos,
trademark information, and such, using
embedded resources means you have to
copy only the .resx file and not the
associated resource data files.
You cannot edit embedded resources
directly. If you try to edit an
embedded resource, you will receive a
message prompting you to convert the
item to a linked resource in order to
edit it. Conversion is recommended but
optional. You must export them, make
your modifications in an external
program, and then import them back
into your project.
Thanks for all the reports, that helped me find more precisely where was the problem:
For me, it was the images used as project icon in the task bar that was built as resources and had to be built as content. All others images can be build as resources, no problem.
Hope this helps for the future.

Categories