Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - Sharing resources file between project

Tags:

c#

resources

I would like two how to do to share Resources files between 2 (or more) projects?

So, to resume, I've three project :

the development project (CF.NET) that include the resource file (with all definition).

I've two other projects that are empty BUT linking to the development projects, it's just a different build each time, so when I modify the development project, all three projects are updated too. (Modification of the csproj file.)

Question is, what about Resources files? When I try to access from the development project I get all resources but when I try from the 2 others, it throws an "MissingManifestResourceException".

Any idea how to solve this issue?

Thanks.


[EDIT]

Here is what I've done :

Create a project named "RealProject" which contains all code (including resources files) Create a project named "LinkedProject" which contains nothing (I deleted all files into it and modify the csproj file as the following :

  <ItemGroup>
    <Compile Include="..\RealProject\**\*.cs" />
  </ItemGroup>

So in LinkedProject directory I've only :

  • [Directory] bin
  • [Directory] obj
  • [File ] LinkedProject.csproj

The whole LinkedProject uses the RealProject files, it's just a different configuration build (see here to know why : C# - Code compiler for .NET & CF.NET )

Once in that configuration, I've no access to the resources files from the RealProject ...

If you need screens or more detailed explanation, just ask.


[EDIT]

With this code, it works, Resource manager isn't loaded on the good Assembly name, but it should exists a better solution !!!

Assembly ass = Assembly.ReflectionOnlyLoadFrom(@"..\..\..\RealProject\bin\Debug\RealProject.dll");
ResourceManager manager = new ResourceManager("RealProject.Properties.Resources", ass);

[Solution]

Things to check :

  • The LinkedProject as the same namespace as the RealProject
  • Add Resources as links
  • Clean up all your solution
  • Rebuild it

Test !

like image 836
Arnaud F. Avatar asked Feb 25 '11 15:02

Arnaud F.


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C language?

C is an imperative procedural language supporting structured programming, lexical variable scope, and recursion, with a static type system. It was designed to be compiled to provide low-level access to memory and language constructs that map efficiently to machine instructions, all with minimal runtime support.

What is the full name of C in C?

Full form of C is “COMPILE”. One thing which was missing in C language was further added to C++ that is 'the concept of CLASSES'. So ++ being the increment operator, C has an incremented version called as “C++”.

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.


2 Answers

Try to add the resource file as a link to the other two projects and make sure the namespaces as defined in the project file is the same.

like image 117
Daniel Hilgarth Avatar answered Sep 21 '22 15:09

Daniel Hilgarth


Try adding existing file in other projects as a link.

like image 45
Jakub Konecki Avatar answered Sep 19 '22 15:09

Jakub Konecki