Automated Build script in VS 2008 - c#

I have built an installer using WiX that consists of multiple .exe files that are 'Release' builds of other .Net projects (VS 2008). Each time I update one of the projects, I build that project and copy the Release build into the installer and then build and release the installer.
I find it a very tedious job to constantly check if the exe's that the installer has are the latest version or not. Is there a way that I can automate this build process so that as soon as I build the installer, it will generate the latest release builds of the associated projects and place the .exe file in the installer project.
I am new to VS and WiX, please advise. Thanks in advance.

You should be able to create a Solution containing:
- all projects which build the EXEs
- the installer project which builds your installer
Once you are there, you should be able to right click on the Installer Project and set dependencies to all the projects which create your EXEs. You should be able to build your Solution with the right EXEs bundled in your Installer.

Arun's solution is great idea, and I recommend it.
We also have a lot of assemblies that we maintain, and rather than copying them around we use symbolic links to minimize the number of build-and-copy actions. You can research mklink (http://en.wikipedia.org/wiki/NTFS_symbolic_link) for details.
We use it like this, but we do this as part of our environment setup, and not part of our build script.
mklink /project1/bin/project1.dll /project2/bin/project1.dll
This ensures for us that project2's reference to project1 is always up-to-date, whenever project1 is build, without needing to copy the file. In our case, project2 and project1 are not part of the same solution, and they have no direct references to one another (we do a lot of plugin-type reflection/assembly loading).
Hope this helps.

Related

How can I copy/use already compiled Dlls into my new build in TFS

I have a very huge application, having more than 400 different projets. Most of them have been developped in very small solutions, much of them having only from 2 to 5 projects and all having a project called "Main", which is the startup project that calls the other one, for loading time purposes and efficiency.
I have added all of those 400 projects to my TFS build definition manually.
Now comes 2 questions :
1- It seems in TFS that my projects needs to be placed in the good build order in my build definition? TFS does not automatically detect the dependencies, as my little NAnt was doing all alone??? Do you imagine having to figure out the right build order for a solution containing 400 projects? This would be easy if they would have been in the same solution, but that is not the case.
2- We use third parties assemblies (Dlls). I have added a folder names "CommonDlls" into my TFS workspace. My builds starts correctly and starts compiling my first projects and sending them into the "bin" directory of the build. Perhaps, when the build trys to compile the first project referencing a 3rd party assembly, it cannot find it... Is there a way in pre-build script to copy the files located in the "CommonDlls" folder to the "bin" outdir of the build? Will TFS use those Dlls when compiling each project or it really tryes to use the referecend path into every single project?
Let's say my project on my development machine as "c:\TFS\bin" as a reference path where are located all dlls, will TFS try to look for that folder or it will use the outdir (it's own created bin folder) ?
The most effective way is to package the DLL's logically into NuGet packages. You can then store them on a file share and configure Visual Studio and you build server to fetch the correct ones at build time. This negates the need to burden your source server with big binaries and allows the server to cache the packages between solutions.

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.
I actually chose a somewhat "middle" solution, the following way.
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.
I built the setup project, and got the MSI file as the output.
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"
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.
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:
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)
Check out the Fody/Costura recommendation from this question:
Embedding DLLs in a compiled executable
It's great! I just tried it out for a similar need and in less then a few minutes I had a completely portable (except the .Net framework) exe that I could easily give to co-workers.

Visual Studio Build Avoidance when building many C# projects

I have a solution with a lot of C# projects. The dependencies are not cyclic and when I build a high level DLL it appears to be rebuilding all the project referenced DLLs that it is linked to before running the program.
This seems to be unneccessary because I did not change the code in those DLLs and they are at a lower level so the changes I made in the top level DLL should in no way effect the low level DLLs.
How can I tell visual studio to only build DLLs that depend up the hierarchy chain not both ways.
Go to Tools->Customize
A dialog will open. Go to Commands tab. In menu barradio select Build | Project only. Assign a shortcut to it and use it.
When visual studio checks dependencies, it runs the build process. This is not necessarily building your project. In Visual Studio, if you navigate to Tools->Options...->Projects and Solutions->Build and Run you will see a drop downs labeled MSBuild project build output verbosity. If you change this to Detailed. When you build, you will see, in the output window, that it is verifying whether or not files have changed in order to determine if it should rebuild the project. This is why it appears to be building every time.
You should use the following setting:
"Only build startup projects and dependencies on Run" under Tools / Options / Projects and Solutions / Build and Run.

How do I publish a Windows Forms Application?

So I made a C# program, and its great and all (its a Windows Form Application). The issue with it, is I don't know how to use it outside of the debug mode form. How do I publish it? My target goal is to create a two folders, put a shortcut to the application in one, along with the other folder which will contain the application and all outside programs (some of the buttons link to batch files). Then I'd want to be able to put it in a RAR compressed file, and upload it online for others to download it.
How do I publish it so that happens? How do I take it out of debug mode?
Go into your project folder, then navigate to /bin/Release. If there's an EXE file with the title of your project in there, copy it somewhere (along with any DLLs that you may have linked) and there's your program. If it's not there, first try Build -> Compile Solution in Visual Studio. If it's still not there, navigate instead to /bin/Debug and do the same thing. Then, copy all your batch files into another folder, put them into the same folder, and RAR it.
P.S. Try not to use RAR, few people can extract them. Use ZIP or SEA (self-extracting archive) if at all possible.
First off, you need to build your application in Release mode, in Visual Studio simply change the drop down near the top of the window to "Release." This will create a bin/Release directory where your sources are located. The folder will contain an EXE for your application and DLLs you need to include. It could (and probably will) include some debugging *.PDB files that you do not want to include -- as those include debugging information.
Copy the contents of that directory somewhere and RAR it up.
Building in x86 Mode
(You should only do this if you have a specific reason to)
If your application uses 3rd party DLLs that are not 64-bit compatible, you may need to do a release build in x86 mode. To do that, click the "Any CPU" drop down and click "New Configuration" (or something like that) and follow the steps to add x86. Then build with the x86 -- Release setting. That will output x86 binaries to a bin/x86/Release folder where your sources are located.
The Preferred Soltuion
Most users are going to prefer some form of automatic installer instead of a simple RAR or ZIP. Visual Studio (Standard/Pro) can create self installing MSIs that do all the work for you. A basic overview is here. You can add shortcuts/etc using the wizards Visual Studio provides.
If you need an even more robust installer you could check out solutions such as InnoSetup or NSIS
To build your application in Release mode instead of Debug, go to the Build menu and select Configuration Manager.
Change the Active soluction configuration to Release. Now, when you build your solution, it will put the executable in the /bin/Release folder.
If you need to automatically perform certain actions once the solution is built, like packaging into a RAR or ZIP archive and copying the distributable to another folder, then check out post-build actions.
After Visual Studio 2010 , Microsoft remove Make setup utility facility from the visual studio and,we have to downlorad that plugin seperatly from
Get InstallShield Limited Edition for Visual Studio
You Have to fill the application
After intalation, goto
Visual Studio-->New Project-->Other Project type-->Setup and Development
You will see follwing screen
Now you can goto InstallShield setup utility and change the things as you requirement.
add all file in debug folder of your project in follwing interface and build solution,
Final setup will locate in your setup folder-->Express\CD_ROM\DiskImages\DISK1**
hope this will help you

how to use VS Setup and Deployment project and build an .msi file to install the program?

i wanna deploy a C# Windows Application project using Setup and deployment project technique
but i don know what should i use
after i open File > New > Project > Setup and deployment > ....
then what ,, what should i do next
In the past I've used the Visual Studio Setup Project or Innosetup for my programs. I prefer to build .msi's over exe's so Visual Studio Setup Project has been my goto for a while now. It is however, very lacking in capabilities. The interface is not intuitive either in my opinion. Every time I build an installer there is a lot of trial and error install/uninstall to get it right. Other's have pointed out WIX and I've looked into it. It appears to be very flexible and since it is open source, we should be able to count on it for the long term.
Here is a recent article about WIX. What I found interesting is the article claims (see link in article) that Visual Studio Setup Project is being End Of Life'd in VS 2010 + NEXT_VERSION. This is a little disconcerting to me. Since I don't want to begin to rely on the new Install Shield "Lite" in VS, I'm going to put effort into learning WIX. I hope it'll pay off in more flexible builds for my applications as well.
All that said, when creating a VS Setup project, I usually use the wizard to put in the initial plumbing. You'll point it at the files you want in the .msi. Typically for me this means the "outputs" of one or more programs in my solution. Any managed assemblies referenced in the programs will automatically get picked up as dependencies and included. Unfortunately unmanaged assemblies don't and I usually have to add them manually using the "File System Editor" mode in the Setup Project UI. Adding shortcuts is a little hokey as well. You right click under the start menu and desktop section of the "File System Editor" mode and select create shortcut. This is all by memory so hopefully I'm getting this right. You will certainly have to test your installer multiple times before you get it just how you want. I like to test under a VM as well.
Finally, the VS Setup project produces a setup.exe and .msi file. Setup.exe is used for detecting and installing dependencies (such as .Net) before unpacking the actual DLL.
When u do this File > New > Project > Setup and deployment >
then right click Application folder> Add > File...and add your app's .exe file and also you can add shortcuts of your app in desktop and program's menu
I would recommend you to go for some tool for creating msi.
I am using WIX
What you need depends on... what you need.
For a large percentage of applications, all you need the installer to do is let the user choose an install location, copy files to a directory structure at that location, and create a few shortcuts. For that, a Visual Studio Installer -> Setup Project is fine. It can handle this basic functionality, as well as installing prerequisites like the .Net Framework redistributables, providing custom install options, and/or writing simple registry keys. The Setup Wizard creates a Setup Project as well, but runs you through a wizard to set up the basics. This is a good option if you've never created an installer before.
If you want this application to be controlled by a larger, more custom install, choose the CAB Project; it will simply pack the necessary files into an archive that is easily accessible from another setup project.
If you are publishing a class library, use a Merge Module. Merge Modules work within install programs themselves, providing files needed for the main application to work.
If you need serious customization, or you want to interface with existing InstallShield logic, I'd get a third-party installer. I've worked with InstallShield before, and it's pretty full-featured, but by the same token, the installers it creates are applications in their own right and can take days or weeks of logic programming to "tweak" to your satisfaction.

Categories

Resources