Posts Tagged ‘C#’

Deploying C# Setup.exe with .Net 3.5 Redistributable

March 4, 2010

Its annoying for end-users when they have to download the .Net 3.5 Framework via Microsofts site when installing your applications:( So why not deploy your app with the .Net framework included!

Here are the steps to add a Setup project to your VS2008 application packaged with a .Net 3.5 installer.
1. Create a new C# .Net 3.5 project (in my case a Visual C#/Windows/Windows Forms Application).

2. Right click the project title (not the solution title), and go to Properties | Publish | Prerequisites.

  • You will see that Windows Installer and .Net 3.5 are selected as default.
  • Now, check ‘Download prerequisites from same location as my application‘.
  • This avoids the end-user have the massive .Net 3.5 Framework internet based download.
  • Make sure the ‘Create setup program to install prerequisites’ at the top of the window is checked.

3. Right click on the Solution title and go to Add | New Project | Other Project Types | Setup & Deployment. Choose Setup Wizard and then OK.

  • In the setup wizard click Next, choose the 1st option in (VS 2008), ‘Create a setup for a windows application’.
  • Next, choose the project outputs. For this example ‘Primary output from myApp’ will suffice.
  • Next, add a readme file if you want (I did not want), and click Next or Finish.

4. Right click the Setup project title (Setup3pt5 in my case, see pic below), go to Properties | Prerequisites.

  • Check ‘Download prerequisites from same location as my application’.

Setup Prerequisites

Steps 5 – 10….. (more…)


Adobe Air to Exe – Packaging Air app in Windows executable

February 23, 2010

In AIR 2 you can build an EXE installer file for distributing an AIR application on Windows. I was getting a good few errors at the start trying this (it was a bit of a pain really), so to ease your experience of AIR to EXE, here are the steps I took to complete the process (btw, its just a fluke it worked out to 10 steps, only numbered it retrospectively!).

UPDATE: Serje Jespers created a drag-n-drop tool to accomplish this task, have a look here

I have a follow-up post also, to show how to package the AIR application EXE file, with the AIR runtime .EXE as a single setup file using InstallJammer! – link

Any Questions? Just drop a comment

Firslty, some of the command prompt error messages I was seeing.

  • -storetype is required
  • unable to create temp file in output directory
  • Java not a recognised command

1. Update your Air SDK from Air 1.x to Air 2 Beta 2(its in Beta 2 at the time of writing, but at least Air 2.0 is needed), and also install the Air 2.0 runtime.

2. Once downloaded, look up follow the steps carefully in How to overlay the Adobe AIR SDK for use with the Flex SDK.

3. In the app.xml file (or whatever your .xml app file is called) in the Flex Builder project, you have to add the following line:

<supportedProfiles>extendedDesktop desktop</supportedProfiles>

Read full post with all steps …..

Microsoft Charts (.Net) – Based on Dundas Charts

February 2, 2010

Microsoft Charting Component was released just over a year ago for .Net (ASP and WinForms), and is based on a cut down version of Dundas Charts API, from whom Microsoft have purchased the IP. The download, with a very good sample gallery, is avialable here. Having looked at all the examples, theyre not as smooth or interactive as the native Flex charts, but good enough all the same.

ASP.Net dashboard example and tutorial is available on Michael Ceranskis site.

According to Alex Gorevs blog, the charting components will be integrated into .Net 4 (he also has some good tutorials).

Unit Testing in C# –

November 11, 2009

I was using NUnit, but it had to be run from the command line or
as an external .exe.

Just installed and its much handier. Your tests
can be run by simply right clicking the project and going to Run Tests.

VBA to C#: Public, Private and Static Variables in C#

August 17, 2009

Was answering a forum question by a VBA programmer about public, private and static variables in C#. (Create a New>Project in Visual Studio 2008, and choose Visual C#>Console Application, name it PublicPrivateStatic_Test, and paste in the code below.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PublicPrivateStatic_Test
    class Program
        public int publicInt = 1;
        private int privateInt = 2;
        static private int privateStaticInt = 3;

        public int getPrivateInt()
            return privateInt;

        public void setPrivateStaticInt(int i)
            privateStaticInt = i;
        public int getPrivateStaticInt()
            return privateStaticInt;

    class OtherProgram
        static void Main(string[] args)
            Program p = new Program();
            Program q = new Program();

            Console.Write("Public int is {0}", p.publicInt);
            //Prints 1, as it is public

            //Console.Write("Private int is {0}", p.pirvateInt);
            //Wont Compile as it is a private variable.
            //Need to use p.getPrivateInt(). Prints 1.
            Console.Write("\nPrivate int is {0}", p.getPrivateInt());

            //Console.Write("Private int is {0}", p.pirvateStaticInt);
            //Wont Compile as it is a private variable.
            //Need to use getPrivateStaticInt(). Prints 3.
            Console.Write("\nPrivate Static int is {0}", p.getPrivateStaticInt());

            Console.Write("\nPrivate Static int is now {0}", q.getPrivateStaticInt());
            //Will print 999 instead of 3. Think of a static variable
            //as only existing once, and p and q both reference it. If
            //instance p changes it, then it is also changed for instance q.

            //Keeps the console open until any-key pressed

Console output:

Console output

Console output

VSTO Design-Time Adaptor error

August 17, 2009

When working with VSTO and creating a new Excel 2007 Workbook project, I got an error that the VSTO Design-Time Adaptor for Excel 2007 was corrupt or unavailable. Just before repairing the install, as is advised, I had a quick check of the Task Manager, and noticed that an Excel.exe process was still running. Ended this process, and hey presto, it fixed the problem.

It appears that sometimes when debugging/running your project, if it fails or stops before the Excel app gets closed by your code, the design time adaptor hangs. This happened to me because an Automation Excetuable had left an instance of Excel up and running in visible = false mode.