C Sharp Development 101 – Application Deployment

1

In this tutorial we are going to focus on deploying an application making it from scratch as the current project we have been developing is only meant for a localhost install, using the users windows login information to access the SQL Server 2008 database.  The deployment will be using FTP and deploying to bnry.ws in a sub folder where it will present the incoming user wanting to download the application with a formatted HTML page that gives them the prerequisites of the application and the option to install it right from the web page.



To begin we are going to make a new application called DeployTest.  After the Windows Form Application has been created we will want to add a button to the form and downsize it to be just slightly bigger than the button itself. After we have our button on the form we will want to name it btnCheck and give the Text value of it something along the lines of “Press Me“. After the button has been named we will need to double click on it to traverse into the event handler for when the button is clicked. Once there, we are going to create a MessageBox to appear on clicking the button to notify the user that deployment to their computer has worked.  The code although minimal is posted below:

// File: Main.cs
// Author: Greg R. Jacobs
// Date: July 1st, 2011

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DeployTest
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}

private void btnCheck_Click(object sender, EventArgs e)
{
MessageBox.Show("Deployment to multiple people worked!", "Congratulations", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}

After this is complete and has been tested we will need to go behind the scenes and prepare the information that is needed to display who the author of the application is and where we are going to want to deploy it to, etc.. This can be found under the properties folder under the Solution Panel and can be accessed by double clicking on the properties folder. This will bring up all of the properties that can be changed on the application organized into tabs along the side:

  • Application
    • Will allow the user to change items that deal with the application information such as assembly info, the start up object, whether or not to include the manifest that is created and the target framework we are going to deploy on.
  • Build
    • Defines whether we will be using the default configuration (debug) or what platform we will develop for whether it be x86, x64 or Any CPU, the level from 1 – 4 to use for checking for errors and warnings, as well as the output path.
  • Build Events
    • This section will allow you to run command line arguments either pre-build or post-build.
  • Debug
    • Lets you specify the action to run when you first run the debugger whether it be just starting the project, starting an external program, or starting a browser with a specified URL.
  • Resources
    • Allows you to add resources in the form of Strings, Images, Icons or Text files
  • Services
    • Will allow you enable client application services which will enable a windows based application to use ASP.NET authentication and profiles services.
  • Settings
    • This section will allow you to store and retrieve property information dynamically
  • Reference Paths
    • Allows the user to search for a folder to add as a reference in your current windows forms application
  • Signing
    • Allows the user to sign the manifests and assemblies involved in the Windows Forms application
  • Security
    • Allows you to specify the access that the application requires in order to run.
  • Publish
    • Allows the user to publish the Windows Forms Application to a specific folder location whether a web site, ftp server, or file path.  Also will allow you to change the application files, prerequisites, updates and options associated with the Forms App. Finally allows you to change the version before publishing.

The two that will be used for the most part in this tutorial will be Application and Publish as they contain all the build information and where we would like to publish our application to. We will first start out on the Application tab and navigate to the button that says “Assembly Information…” and click it. A forms box that looks like the one below will appear and we can start to fill in the boxes with the correct information.

After this is completed we can press OK and move onto the Publish tab where we will start the deployment process.  When we first arrive on the tab we will notice that a publish folder has been chosen with the default being within your project.  This will have to be changed as not many people have access to your projects folder and it would be even less desirable for then to mess something up if as your code is only a few clicks away.  We will want to change that to an online resource so that anyone on the web can access our content if we so desired.  To do this click the button besides the Publishing Folder Location TextBox labeled “…” and the following should appear:

We will need to use and FTP site and use some authentication to be able to create our files and folder structure on the server.  So once we have clicked FTP Site along the side of the the image below should appear.

I will be using my hosting account at bnry.ws and using the default port of 21.  I have chosen to create a file folder structure just for applications as I plan on making many more deployable applications. I have also chosen to omit my username and password as the FTP server you will be using will have your username and password to enter.  When this is completed we can now press OK and you will see that the Textbox that previously had “publish\” is now updated for the path to the FTP server and its deployment location.  For the installation Folder URL we are going to use the same address as above but change the “ftp://” to “http://“.  For the Install Mode and Settings we will want the application to be available offline, which means that it will be launchable from the start menu. The buttons along the side of this section will specify what application files must be installed with the program, what runtimes are needed on the clients computer (and if the client computer doesn’t have them, it will offer to download them), How to roll out updates to the user (whether before or after the application starts, and will allow you to put a different URL for updates if you so choose), as well as an options button that can specify publisher, product, support page, default page for deployment web page that is generated, etc..

Used to specify what files will be installed

Frameworks and runtimes that must be installed for application to run

How the updates will be installed to the client computer

Make little tweaks before your deployment

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

All of these can be modified to your liking as you can see I modified my options folder to change the Publish Language to English, Publisher Name to Binary Wasteland, Product Name to Deploy Test, the Support URL to the comments and suggestions section of Binary Wasteland, and the Deployment Web Page to default.html. You will also notice that I have checked Open deployment web page after publish so that when the publish is complete you may start sharing your application right away. I have also checked Verify files uploaded to a web serverso that we are not setting users up for disappointment on possibly corrupt files. After this is modified to your liking we can press the OK button.

The last section is Publish Version which will allow us to version our application which could tightly integrate to the Updates button and not allowing an application to run unless it has a minimum version installed or it must be the most up to date application. After we have set the publish version we can now press the “Publish Now” button. After it is clicked you should see the following prompt:

After entering your username and password and pressing OK the application will publish the application and create the web page we directed it to earlier. The web page should look along the lines of this:

After this is complete and the users can navigate to your deployment web page, all this is needed is for them to press install and it will prompt the user to install the application. I will proceed with the install and post a series of pictures to step you though what the user will see when installing.

After the download has complete we will want to double click the .exe and it will verify the published files and throw a security warning because our application publisher has not been verified. This is fine as we don’t currently have a certificate to verify Binary Wasteland as a publisher, so we will press the Install button and proceed with testing our DeployTest application.

It will quickly install the application and run it after it is done installing giving you something that looks like the below two pictures, one being when the button is pressed and one when it is not.

Application before being clicked

Message Box after button has been clicked

 

 

 

 

 

 

 

With this application complete and working on more than one users computer using Visual Studio 2010 and the publishing features included in the software we now conclude our C Sharp development 101 tutorial series. We have come a long way from installing the basic IDE to developing a Windows Forms Application to deploying an application on multiple computers using publishing software developed by Microsoft. Hopefully the knowledge you have gained throughout these tutorials will provide a foundation for the Development 101, 201 and 301 series to come. Until the next tutorial series, Happy Hacking!

Share.

About Author

Master Chief of Binary Wasteland, Freelance Programmer, Software Development Writer, Microsoft Enthusiast, Open Source Evangelist, and lover of good code.

%d bloggers like this: