Merging two related projects to one executable? (c sharp) - c#

I'm currently working on a solution with two different project. One project is a windows form (main project) and the other one is a console application. Currently I am running the console application from the main project with:
System.Diagnostics.Process.Start(Environment.CurrentDirectory + "\\console.exe");
When I debug, everything works fine as a wish. However, C sharp creates two different executables, one with the console and another with the main project. My question: is there a simple way to merge those two to only one executable? Note: I am a beginner, and I tried really hard to get this working :(
Thank you!

To merge multiple assemblys into one you can use Fody/Costura. It allows you to merge multiple assemblys(exe's) into 1 project(exe). In your main project you add it (can be done via nuget). Then just in weavers.xml (file that will be automaticly generated add these text:
<Costura>
<IncludeAssemblies>
MyProject.MyConsoleApp
</IncludeAssemblies>
</Costura>
(it should be the same name as the reference, so add the console app to your windows form as reference,and remember don't add the .exe suffix)
PS: read the tutorial on the link I gave you.

Related

Where can i run my code in visual studio?

So, i am trying to write my first C# "Hello World" Program in visual studio, however when i want to see the output of the code (or simply just run it), i can't because i can find the run option, i have tried ctrl + f5, and many other options, however it didn't worked any suggestions? Here's a picture of my visual studio.
Check this guide Tutorial: Create a simple C# console app in Visual Studio
Open Visual Studio 2019.
On the start window, choose Create a new project.
On the Create a new project window, enter or type console in the search box. Next, choose C# from the Language list, and then choose Windows from the Platform list.
In the Configure your new project window, type or enter Calculator in the Project name box. Then, choose Create.
And then to run:
Choose the green Start button next to Calculator to build and run your program, or press F5.
This is because you created empty solution. You don't have any output, i.e. process of compilation of your solution does not produce any executable (exe) or library (dll).
In order to run any code is to produce one of the above. In order to do that you have to have project created.
To do so, you have to (in your case) right click solution and choose "Add -> New Project" option. This will show you pop up allowing you to choose which project you want to add, choose just basic type of project, which is "Console app". There you will have class with static method Main which is the entry point for your app.
Code inside Main method will be executed.
You haven't created a project. You've got no executable and no ability to build one. I don't know if you've worked with other languages before or not (perhaps ones which are interpreted and/or have no specific structure to them), but C#/.NET programs require a particular structure in order to build and execute. You can't just create a random C# file on its own and execute it.
Instead, create a new Console Application project (from the File -> New Project menu) and give it a name.
That will auto-generate a Program.cs file, which contains the Main method which is the entry point of your program when it's executed. From there you can write code in there, create other methods in that class if you need to, and you can also add other files containing classes etc. into your project.
(There are, as you'll see, also quite a lot of other project types you can create depending on the kind of application you want - and also some types which are just for code libraries and not full applications.)
How to: Run a C# program in Visual Studio
The project should contain a C# file with a Main method, and its output should be an executable (EXE), you have created an empty solution with no such files.

debugging several projects in Visual Studio 2017

I have a solution mainly written in c sharp. This solution has 10 projects, one of them contains the web forms. This web forms get the data from another project. However, I am receiving null data. In order to debug this, I would like to setup the web forms project as the start project but the problem that I'm getting is that I don't see what is going on on the other project, the one that passes the data. How can I reach this project when debugging? Any solutions? The other project just contains classes, it is not dealing with the database either yet.
Thanks
Have you tried to set the solution to start multiple projects at once?
Right click on "Solution Explorer", click on "Properties", select "Multiple startup projects" and choose what projects you want to start together by changing the dropdow from "none" to "start". It should work.
sorted! it was a silly mistake, the interface was misspelled, it should be IClass, being Class the class name, somehow, it was misspelled

C# - generate DLL linked in console App

I have two C# Applications
TestApp is a console app which call a method decrypt included in AppCrypt
AppCrypt contains this method and needs to log (write on a file)
So far I can modify TestApp and I saw the result on my console but my goal is to edit the code of AppCrypt
I am using VS for both.
Question 1) I cannot find where is written the place where I link the DLL of AppCrypt
Question 2) I can build AppCrypt but I cannot generate a new DLL because I am getting this message
I found on SO that I should add a project Console App or a Winform but I just need to use that function without having a proper app so I dont know if it is my case.
I have built the DLL but it does not seems to be linked in my console app which is TestApp, how can I verify that it is linked?
You are getting that error cause most probably you have set your class library project as Startup project in your solution. Whereas you should set the Console app as your start up.
How to Set a project as StartUp: Right click on your project name and from context menu select Set As Startup Project

Start multiple instances of console app in Visual Studio (with different args)?

This question ...and the answer shows how to start another instance of a console app in Visual Studio when you already have one running.
I want to do the same BUT passing different args[]. For example, when debugging I want to start up 2 instances of MyConsoleApp.exe as follows...
"MyConsoleApp.exe Agent1"
"MyConsoleApp.exe Agent2"
Does anyone know how to do this?
(Using Visual Studio 2015 Pro)
As far as I know you can't. What I'd do is open the solution in two VS instances and run it. Or else you can give it a go the following way too ( haven't tried this but ideally it should work)
Create two console projects and add all your files as 'linked' files on both projects ( the same .cs files being used on both projects)
Go to the solution and set one project as 'Start with Debugging' and other as start without debugging. ( or may be both as Start with Debugging- depending on your scenario) here is how you could do this.

Merging 2 Windows 8 Store App Projects

For a school project we developed 2 different projects (2 solutions). Now we need to merge them together to form 1 Windows 8 Store App.
I added Project2 to the solution of Project1. But I ran into some issues.
Each project has an .appxmanifest-file. If I keep both files, VS 2013 will complain because the logos are set in both projects. The error message is:
Payload contains two or more files with the same destination path
'Assets\Logo.scale-100.png'...
I tried deleting 1 .appxmanifest-file but then VS complains about missing the file.
Deleting the logos out of 1 manifest also gives error messages.
How can I merge these 2 projects without these issues?
Basically you can't.
This type of project is designed to work as standalone application so you can use them both in one solution.
What you should is to decide which one you want to leave as main project, then add "class library project" to this solution and import all needed files from the other solution

Categories