Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to statically share code between projects in C#?

Is it possible, in C#, to share code between Visual Studio projects without needing to distribute a DLL?

I'm maintaining some software that's composed of a few Visual Studio C# projects, each building to a simple console executable. There's a lot of shared code between the projects that I'd like to move out. I believe I can put the code in a Class Library project, but I'd rather avoid tacking on a DLL to distribute with each of the executables.

Is there any way around this? I'm new at C#, so perhaps I'm thinking about this all wrong anyway - are there any alternate suggestions?

like image 641
Eric Avatar asked Oct 05 '11 16:10

Eric


People also ask

How do I share code between projects in Visual Studio?

If you select Start Collaboration session from the Session Details menu, an invitation link to your session will automatically be copied to your clipboard. You can share this link with anyone you'd like to collaborate with, as long as they also have VS Code and the Live Share Extension Pack downloaded.

Can two projects reference each other C#?

This can be achieved by adding reference of one project in the other project. If both the projects are in the same solution, then expand the project name, right click on 'References', click on Add references. Go to 'Projects' Tab, select the project name which you want to use in current project, click ok.

What is shared items project?

You can think of “shared items” projects as another way of organizing your files in case you have many projects building the same source file (e.g. in case you build multiple applications that share the same source and you're not already using static libraries for this purpose).

How do I share a CPP file?

Use a zip program, and zip the executable and the cpp source file into one file. You can then send it without the browser complaining. It's best to let the person you're sending it to, know what you sent, and maybe even the size of each file, so they know what to expect.


1 Answers

You can use ILMerge to combine the class library with the exe.

http://research.microsoft.com/en-us/people/mbarnett/ilmerge.aspx

like image 73
Sean Kearney Avatar answered Sep 30 '22 18:09

Sean Kearney