Compiling one .exe file from 2 projects - c#

I have a c# solution that holds 2 projects (1 for the codes of data handling and 1 for the winform UI) the desktop project also holds an access file in its bin folder.
My question is, how do I create an .exe file of the solution that I can send out and it will work?

From your requirement, what I understand is you need to embed the dll in the exe. From VS Project(Your exe project) Properties -> Resources -> Add Resource -> Add Existing File

If UI project refers to "data project", on compilation of UI project in its Debug or Release (based on compilation configuration choice) folder you will find all binaries you need to run UI.
Will this work simply copy/paste on client machine noone can say other then you, as it strongly depends on how your program works.

Related

Where do I put a folder that is used in my C# application?

I'm planning on my C# application having a folder called Data that is reused whenever the program is launched. I put it in the root of my Visual Studio solution which causes it to be where you see below
MyProject (File folder)
bin (File folder)
Debug (File folder)
MyProject (Application)
.
.
Data
obj
.
.
.
.
after the project is built ... but I'm guessing I'd want it where the actual application is, right? Or is it proper for me to instead have a "Create if doesn't exists" for that folder in my application? Sorry if this is considered a subjective question.
1) you may check it at the start of the program if it doesn't exist then you may create it.
Right click on your SOlution in visual studio>> Add new project>> Under other project types>> Choose>> Setup and deployment >> Visual Studio installer >> Set up project.
Setup projects are important in many cases, when you need to make any changes for first time installment or need to modify registry, need to copy some data folder or other settings for the first time.
2) Create a setup project and in your setup project you may create that data folder, which will be created when user will install the application.
I would prefer to use both option to avoid any issue in future.
From what it looks like in your example the data folder you created in your application/solution explorer. So far so good but it wont ever be created inside your project.
You have 2 options if you want it to be in the same directory as your application.
You create a .txt file or whatever you want to put into it later on in the solution explorer and say "copy always" in the properties
Is you create your folder manually inside your program. The base location of your program is usually AppDomain.CurrentDomain.BaseDirectory. Thus you could use Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + folderName).
For 2 this could be done on each run on the program (if the directory does not exist yet OR on setup of the program if you have a special setup routine).
As far as I'm aware all of these variants are legit and are dependent on your exact use case and personal taste.
I'm guessing I'd want it where the actual application is, right?
NO! Let's say you eventually bundle this program into an installer the puts it in it's own Program Files folder. Standard Users do not have write access to anything under the Program Files folder!. You just forced your program to require Administrator rights every time it runs.
Instead, you need to put your data folder in the Application Data special folder:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

.NET (Visual Studio) Share assets between projects

I'm working with Visual Studio. There I have a solution with several web-projects (.net MVC 4). All of these web-projects use the same javascript-libs. Currently I copied the library into each project, but this can't be the final solution. What is the best approach to share those library (assets in general) between all of the projects? Just link them? Or is it possible to create a project and reference it in all projects?
Update
"Link" the javascript files from another project is not a possible solution as I would have to link thousands of files (one of the libraries I am using is ExtJs) what makes it impossible to build a project without freezing visual studio...
Possible solution
Currently I have a (Web) MVC Project called "Web" and a (Class Library) Project called "ClientScript" which contains all the JavaScript files which are shared between several Web Projects. As linking all the needed JavaScript files is not a possible solution (because it's a matter of thousands of files what causes visual studio to freeze) I copy all the needed JavaScript files to the individual Projects using the Build Events in each Web Project (Project -> Properties -> Build Events -> Post-build).
My Post-build command line in the Web Project looks like this:
start xcopy "$(SolutionDir)ClientScript\Frontend\*" "$(SolutionDir)Web\Scripts" /r /s /i /y /D /E
Every time you build your Web Project all the changed Javascript files get copied from the ClientScript Project to your Web Project.
While developing the Javascripts I run a small "filewatcher" tool which automatically copies a file from the ClientScript Project to every Web Project when it changes. This way I don't have to build the Web Project every time when I make a change to one of the Javascripts.
Anyone that stumbles across this question here in the future should know that there are now Shared Projects in Visual Studio to solve this problem. Universal Windows projects use them by default and you can create your own by downloading and installing the VS extension here: https://visualstudiogallery.msdn.microsoft.com/315c13a7-2787-4f57-bdf7-adae6ed54450
Note: At this time they can be picky about what type of project you try to add the shared reference. I created a JavaScript shared project to share js files between a Windows store js app and an MVC web app and it would not let me do that saying they had to be of the same language. (It supports C#, C++, or JavaScript).
Place the JS files in a single folder, likely above all others, and add them to the project but use the "Link" option. It's part of the drop down on the "OK" button in the "Add existing item..." dialog.
When you run every new ASP.NET MVC 4 project it's take a new port then other app have take.
I simply suggest you a simple thing.
run a project which contain all the pacakages. open them webmatrix and run them as localhost:80.
You need to set the port in settings section of your site in webmatrix. Now it will rechable at localhost now you can reference all the libraries from this packages.
Slightly older thread, but I have another way of doing a similar thing using Web Essentials, that handles the issue of not publishing correctly.
I have a shared folder outside of the projects that require the shared file, normally a 'common' project with other things in as well, but can be just a simple folder as suggested by Michael Perrenoud.
However instead of 'Add as Link' I have been creating a new bundle in the project that requires the shared js/css file, with the same name as the shared file, and then referencing that file in the shared folder using a relative reference location rather than the root based one it starts with.
To add a file from a shared folder in the root of the solution to the scripts folder use the following code in a new bundle file (*.bundle), changing the folder/file names as required.
<?xml version="1.0" encoding="utf-8"?>
<bundle xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://vswebessentials.com/schemas/v1/bundle.xsd">
<settings>
<minify>false</minify>
<runOnBuild>true</runOnBuild>
</settings>
<files>
<file>../../MySharedFolder/my-js-file.js</file>
</files>
</bundle>
Then every time you build it recreates the bundle with the latest version, this version is then also published as expected :)
You can even create a minified version if desired by changing 'minify' to true. Or better yet you can add them loads as a bundle too if you want, you have that flexibilty.
This is an older thread but due to complex business requirements these days applications are divided in to different modules or sub projects.Thus, brings us the need to share common resources like JavaScript files, themes and CSS style sheet files.
I personally feel that common files should be put in separate Asp .Net MVC 5 project which has following structure :ASP.NET MVC5 folder structure
Now the best part is you can separately manage the dependencies using Bower,NPM or Nuget package manager.
After you have organised all the files in this project host this project to your own CDN or may be on cloud. You can use Using CDN in Bundle Approach to get script or link references.
That will help you sharing common resources across all the projects.There us a short coming though if you have many developers on the team and if someone added incompatible version lib can affect all the apps.

Creating a .dll file in C#.Net

I had created a project which is C# console application project for which I need to call this project dll in another windows application project. I had built the project in visual studio 2010 and checked for .dll file in bin\debug folder, but it is not created.
But a manifest file and .exe file havebeen created. Please help me out how to create the .dll in this case?
You need to make a class library and not a Console Application. The console application is translated into an .exe whereas the class library will then be compiled into a dll which you can reference in your windows project.
Right click on your Console Application -> Properties -> Change the Output type to Class Library
To create a DLL File, click on New project, then select Class Library.
Enter your code into the class file that was automatically created for you and then click Build Solution from the Debug menu.
Now, look in your directory: ../debug/release/YOURDLL.dll
There it is! :)
P.S. DLL files cannot be run just like normal applciation (exe) files. You'll need to create a separate project (probably a win forms app) and then add your dll file to that project as a "Reference", you can do this by going to the Solution explorer, right clicking your project Name and selecting Add Reference then browsing to whereever you saved your dll file.
For more detail please click HERE
You need to change project settings. Right click your project, go to properites. In Application tab change output type to class library instead of Windows application.
Console Application is an application (.exe), not a Library (.dll). To make a library, create a new project, select "Class Library" in type of project, then copy the logic of your first code into this new project.
Or you can edit the Project Properties and select Class Library instead of Console Application in Output type.
As some code can be "console" dependant, I think first solution is better if you check your logic when you copy it.
Creating DLL File
Open Visual Studio then select File -> New -> Project
Select Visual C# -> Class library
Compile Project Or Build the solution, to create Dll File
Go to the class library folder (Debug Folder)

Publish Program in Visual Studio

I'm new to using Visual Studio, and I'm trying to figure out how to 'publish' my program so I can move it other's computers and run it from there. I'm not sure if it makes a difference, but there are three projects in my solution. And if I publish it, will I still continue to be able to develop the original files etc?
Thanks a lot!
Ok, so you've written your code, debugged it and now you want to distribute it...
When you build a solution using Visual Studio the compiled output of each project is produced in a folder which is either specified manually, or, by default, in a bin folder relative to the projects root folder. Within this folder are subfolders which hold the output for a corresponding build (for instance the Debug folder contains the Debug compilation output).
If you have three projects then, for example, let's assume one is an executable application and the other two are dynamic link libraries on which the application project is dependent, the compiled output from the latter two projects will automatically be copied to the applications compiled output folder, meaning you only need to ship what is in this folder (along with anything else you actually know is required).
For a (rough) folder graph to try and visualise what I'm saying:
SolutionFolder\
ApplicationProjectFolder\
Bin\ <- contains overall output
Debug\ <- the compilation you develop with
Release\ <- the compilation you distribute (after testing)
DynamicLinkLibrary0Folder\
Bin\
Debug\ <- automatically copied to 'ApplicationProjectFolder\Bin\Debug'
Release\ <- automatically copied to 'ApplicationProjectFolder\Bin\Release'
DynamicLinkLibrary1Folder\
\Bin
Debug\ <- as above
Release\ <- as above
You can continue to work on your code after distributing, yes, of course, but you can hardly expect the users of the application to have your latest changes without redistributing the whole thing, or updating/patching et cetera.
Of course, this solution is the simplest form - ideally you'd want an installer project as part of the solution, which is the final distributable end-product.
As I said above, it seems you may need to know a heck of a lot more than this to proceed competently and confidently, and I could explain further details on each aspect mentioned here, no doubt, but it has to stop somewhere. Hope this gets you started, though.
Adding to the answer given by #Mr. Disappointment, you could also add a Setup project to the solution, which will take the compiled output and build an installer (a .msi file) for your program. You can then give the .msi file to your users and they can run the setup program to install the application on their computers. You can also put the .msi file on a network share or make it available for download from a website, depending on your requirements.
Another option is to investigate Visual Studio's ClickOnce deployment, which also allows you to distribute your application to users in a simplified way, via a web site or network file share.

ClickOnce & References

I have created a ClickOnce Solution with VS2008.
My main project references another project who references COM dll as "links".
When I build my solution in VS the dlls from the orther projects are moved in my bin folder but when I publish and launch the project these files are not presents in my Local Settings\Apps\2.0... folder.
I know that I can add each dll of the other project as a reference of my main project but I'd like a cleaner solution ...
Is it possible ?
First add those files to your project directly.
Then goto Application properties -> Publish -> Application files
Select "show all files" if you do not see the files you need and then set their
publish status to "Include" NOT "Include (Auto)". This is important or they will not be added.
Please note if you update the files, you will have to remove them and add them again
and set their publish Status again. This is a small bug.
See a previous question of mine for more info:
ClickOnce - Overwriting content files
You need to open the "Application Files" dialog in the Publish tab of your project. From there you can set the publish type (Include, Prerequisite, etc.) of each of your files.
If it's an unmanaged DLL, you'll need to add the actual .dll as a file to your project and mark its build action as "Data". You can then set the Publish Type of that file to Include.
I had the same issue.... and the only way to fix this after going through many options, was by adding those dlls to References.
It works, but I hope there would be a cleaner solution to it in future.

Categories