Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Visual Studio resolve and include all the dependencies of my project during build?

I have a large solution currently under VS2010, with lots of projects and dependencies. Some of them are installed to the GAC, some of them are just included from a "lib" folder. I need to build one of my projects (specifically a WinForms app) to able to run on any, non-development computers without any installation process (except for the .NET runtime of course), just as portable apps do.

For this to work, I need to have all of the referenced DLLs and their whole dependency tree in the output folder of my EXE. I can do it for exemple by marking the dependencies to "Copy local" in the properties window, but that works only for the direct references of the EXE project, so it's far not enough. Another way is to make a setup project, but my client and also I want to avoid that (in the final version I'm gonna use ClickOnce). Of course I can always do it purely by hand, gathering all the DLLs manually, but that's quite a nightmare.

Is there some tool, msbuild trick, command-line option, whatever hack to force Visual Studio to gather the whole dependency tree of my EXE during build, and copy them to the output folder? So that I could just ZIP everything together and send to my client.

like image 996
Zoltán Tamási Avatar asked Jul 04 '13 22:07

Zoltán Tamási


People also ask

How do I create a build and run solution in Visual Studio?

Build and run your code in Visual Studio To build your project, choose Build Solution from the Build menu. The Output window shows the results of the build process. To run the code, on the menu bar, choose Debug, Start without debugging. A console window opens and then runs your app.


2 Answers

I actually chose a somewhat "middle" solution, the following way.

  1. I created a "dummy" setup project, not caring about setting anything but adding the project outputs (primary output, localized resources, contents, etc.). It was a 2 minute task this way.
  2. I built the setup project, and got the MSI file as the output.
  3. I've extracted the contents of the MSI file to a specific folder, called "MyAppPortable" for example. I found the solution here. The command-line command is

    msiexec /a "absolute_path_to_my_MSI_output" /qb TARGETDIR="absolute_path_to_my_desired_output_folder"

  4. I got the full application with all of its resolved dependencies (except for late-binding dependencies, but I took care of them manually, by adding them as references to my projects). I could ZIP the whole folder, put it on another computer, and voila, everything worked fine.

like image 88
Zoltán Tamási Avatar answered Sep 29 '22 07:09

Zoltán Tamási


Basically, using Visual Studio, you can set all of your Solution's Projects to build into the same Output folder and use this folder as your Windows Form application folder (where the application EXE will reside).

By doing this, you will coordinate all of the possible assemblies references that your app is depend on.

In VS 2012, right-click on a Project => Properties => Select Build (left pane) => Set your Output path:

Output path in VS 2012

I would select a a solution-level folder as the Output path.

And if it's prohibited to perform such a modification at your workplace so I would suggest you to use dependency analysis tools like the following in order to interrogate and gather the appropriate assemblies that your app is depend on and will require at run-time:

  • Dependency Walker
  • NDepend
  • Red-Gate Reflector

Update:

Using the above mentioned tools will not yields assemblies references which are late-bounded (at run-time), for this case you may use: Fusion (the Assembly Binding Log Viewer)

like image 20
Yair Nevet Avatar answered Sep 29 '22 06:09

Yair Nevet