Making a C# project DLL and EXE - c#

I'm working on a project where I need to have both an executable so that the user can run a configuration interface and a DLL that can be embedded in other projects to use some of the other features. Is there a way to make Visual Studio produce both an executable and a DLL (as opposed to switching it manually every time)?

I agree with TJMonk15, but i think this should be explained explicitly. You should have two projects, one project that is a DLL, and one that is a normal project. The DLL project should have all your re-usable code. The normal project should be the application you are building, which will reference your re-usable DLL. This way you can build a framework in the DLL project that can be used for any of your future projects.
A good example of this is when you are making a game. Your game engine would be the DLL, and the game you are making would be the executable project. The executable project will contain all the non-reusable traits such as game GUIs and content.

Why wouldn't you put most of the code in one project (With an ouput of type Library) and then write an executable that referenes the DLL?

Related

Multiple Language Projects in Visual Studio

I've recently learned of the joys of compiling projects into dlls to use them in other projects! However, now I'm trying to streamline a process where I have two projects, one written in C# and the other in VB, where the C# project has dependencies on a dll compiled from the VB process.
What I'm hoping I can achieve:
- Have both of these projects viewable within the same VS project
Pull updates on the VB code from SVN and compile them into a dll located
in a folder within the project
Not have to update my references in the C# project as I am updating the same dll in the project.
Build the C# project whenever needed, without rebuilding the VB project
Can this be done?
Thanks!
Is this a VB.NET project? If so, you're in luck.
1) You cannot have a Visual Studio project that uses multiple languages (unless you count ASM in C/C++). However, a single Visual Studio solution can have multiple projects where each project uses a different language.
2) If the projects are C# and VB.NET (or F# or Managed C++ or any other language that produces a .NET assembly), there is little difference in the output assemblies of one versus the other. A C# project can reference an assembly built with VB.NET and vice-versa.
3) If the projects are in the same Visual Studio solution, you can use Project References instead of Assembly References. Project References make it so that one project depends on the output of another project in the same solution. You establish the project reference once (in VS2015: Right-click Project => Add => Reference... => Projects => select the project to reference). And then Visual Studio/msbuild automatically knows the correct order to build them (and whether or not to build them at all). It's even smart enough that if you change the output location of the referenced project, you don't need to do anything to the referencing project.

Compiling a C# project as DLL for Unity3d

As far as I know a C# project can be added to Unity3d in 2 forms. As DLL or uncompiled project.
What are the pros and cons of both? Will they work cross platform (Android/iOS/WinPhone)?
To compile as DLL - do I just use MonoDevelop or Visual Studio to new class library project and select .NET 3.5 and compile?
How do you add a uncompiled project to Unity3d?
Will they work Cross platform(Android/iOS/WinPhone)?
Yes. You can create a library project in Xamarin Studio/MonoDevelop/or Visual Studio. If you do not include platform-specific functions, it will be then cross platform.
To compile as DLL - Do I just use MonoDevelop or Visual Studio to new class library project and select .NET 3.5 and compile?
See this tutorial.
Well Well Well too many question in a single post. Try to answer one by one:
Unity Offical Docs provide much help:
Question
As far as I know a C# project can be added to Unity3d in 2 forms. As DLL or uncompiled project.
To compile as DLL - do I just use MonoDevelop or Visual Studio to new class library project and select .NET 3.5 and compile?
Usually, scripts are kept in a project as source files and compiled by
Unity whenever the source changes. However, it is also possible to
compile a script to a dynamically linked library (DLL) using an
external compiler. The resulting DLL can then be added to the project
and the classes it contains can be attached to objects just like
normal scripts.
It is generally much easier to work with scripts than DLLs in Unity.
However, you may have access to third party Mono code which is
supplied in the form of a DLL. When developing your own code, you may
be able to use compilers not supported by Unity (F#, for example) by
compiling the code to a DLL and adding it to your Unity project. Also,
you may want to supply Unity code without the source (for an Asset
Store product, say) and a DLL is an easy way to do this.
More
What are the pros and cons
About dll:
Pros
You can build DLLs separately.
It could be faster to re-build one DLL
Cons
Calling code from DLL is slower
It would be slower to re-build hole project with all DLLs
Function names are visible. It is easier to reverse code that uses
dynamic DLLs
You can find more on here, here and specially on Google, our best friend:)
How do you add a uncompiled project to Unity3d?
Ans: What do you mean by uncompiled project? You mean scripts? then it is usually Copy\Paste inside asset folder simply.
When you open your Unity project in an IDE (for example Visual Studio), it is a solution with two projects, one for game scripts and one for editor scripts. You can add more projects to the solution through your IDE of choice. In order for this to work, you need to set projects target framework to one that is compatible with Unity (which uses a subset of Mono), for example Unity 3.5 .net full Base Class Libraries. Unfortunately .NET PCL is not supported.
You can reference your (or third party) library in any of the projects as usual, just remember it also has to be compatible with Unity.
Wether your code will work on all the platforms actually depends on what you use. On platform specific limitations refer to http://docs.unity3d.com/Manual/PlatformSpecific.html.

How to copy C++ dependencies into C# Project output?

I have a C++/CLI project that has a dependency on a .dll file. I've set up a post build step to copy the .dll to $(OutDir), which works great when building the project.
Now, I have a C# project that references the C++/CLI project, but the .dll isn't copied to the C# $(OutDir).
There must be a way to just reference a C++ project without having to explicitly know about it's dependencies, right? It feels really icky to have to have my C# project directly reference into my C++/CLI project's dll folder. On top of that, it seems very error prone. I have two C# .exe projects that are referencing the C++/CLI project, so I (or a team member) have to remember to update the references to both C# projects if we end up with a new .dll reference in the C++ project...
Maybe some way during the C++/CLI project build to copy to the "parent" or "master" project output directory? I'm a C++ n00b and only somewhat familiar with the msbuild process, so any thoughts or solutions are welcome!

How to use wixlibs as file references with support for different platforms?

I just am trying to replicate my distributed C# project structure to WIX setup projects. Now there is the following problem:
LIB: a C# library solution that builds AnyCPU .NET dlls from several C# projects
APP: the dlls from LIB are referenced (as file references) by this main application solution. Additionally there are platform dependent libs included in this application solution, therefore it is important to being able to create setups for the two specific target platforms x86 and x64.
Now I started to create a wixsetup project within the APP solution (which works fine). Then I proceeded with creating a wixlib within the LIB solution that references the LIB .NET dlls into the wixlib.
Now the problem:
The wixlib references the AnyCPU .NET dlls within a DirectoryRef which seems to be platform specificly tagged when creating the wixlib. Therefore I have to go back to the LIB solution, build the project with one platform target, copy the built files (via SVN externals mechanisms) to the APP solution, build this project with the exact same target platform as the wixlib was created with and repeat this procedure for creating the other platform.
It may seem that this is kind of complicated, but doable. Due to the fact that I omitted several other library solutions for which the same problem applies and the fact that all those libraries are used in multiple application solutions and - finally - everything has to run on our build server automatically as well, it is clear that this will not work.
I know of the following solution, though:
Double the .NET dll references within wixlib to assign them to different DirectoryRef INSTALLDIR and INSTALLDIR32 e. g. and to implement those different directory references in the wixsetup.
But this would complicate things as well and is not my preferred solution therefore - if there is an alternative.
If there is no smart alternative, just tell me and I will do things as described in the last paragraph.

How to share code between projects of different types in visual studio?

I know there is someone who has post some questions like this. But my problem is a little different.
My program has two versions, one is for PC and the other one is for Windows Phone. In my case, they both use a same algorithm. I want to share the codes between two projects.
First, I tried to create a project containing these codes, then add them to my projects as a reference. But here is the problem, if i create a Windows Form Application project, I can't reference it in a WP project, and vice versa.
Second, I tried to add these codes to my projects as a link. But I have lots of files to share, I don't want add them one by one. And these shared files will mass my project directory.
What should I do?
You need to create a "Portable class Library" project and put your common code in there. it will create a dll. Reference it in other projects and it will work fine.
Using the Portable Class Library project, you can build portable
assemblies that work without modification on the .NET Framework,
Silverlight, Windows Phone 7, or Xbox 360 platforms. Without the
Portable Class Library project, you must target a single platform and
then manually rework the class library for other platforms. The
Portable Class Library project supports a subset of assemblies from
these platforms, and provides a Visual Studio template that makes it
possible to build assemblies that run without modification on these
platforms. - MSDN
sounds to me like you need to make a Class Library project. Create that and you can put in whatever code you want, then compile it to a dll, and reference it in any of your other projects.

Categories