Saturday, April 15, 2017

WIX- Publish an Automated Website

Develop a wix, which can be scheduled in TFS & which can take the setup files from TFS & publish automatically.


  • Install Wix to get wix project templates in VS.
  • New solution, create new web application & publish it.
  • Add new project to solution, project type Wix-Setup Project.
  • Product.wxs is the default file, where you have the product information, name,GUID & what all files to be included as part of the product.
  • You have to setup the Dialogs via UI's and IIS ROOT configuration to publish the web site, which is going to be defined in Fragment sections individually.
  • Before that you have to include, IIsExtension, UtilExtension, NetFxExtension to Product.wxs.
  • Setup the fragments carefully & Dialogues.
  • Create a new file called wix include file (.wxi), which contains the default settings for the app.
  • Create a new file called "InstallUI.wxs", which holds the actions for the buttons exists in UI Fragment.
  • Create a new file called "Setup.build", which holds PropertyGroup, ItemGroup, Targets saying Build, PublishWebsite, Harvest, WIX (these are all names of Targets) with in the Project Tag.
  • In PropertyGroup, Check <Publish> to add the code published folder & <MsiOut> tag is the name&path of the folder where the output is going to be stored.
  • After successful completion of adding the items to the wix project. Do a recheck of things in files.
  • Go to Start-VS-Developer Command Prompt.
  • Move to the location of Setup.build file on the wix project.
  • Try executing the following command:
    msbuild.exe /t:harvest;wix setup.build
  • It will complete the execution if it dont have any setup errors, else check the error info to fix it.
  • Next, go the output directory you 've specified in <MsiOut> in PropertyGroup tag of Setup.build file, and you can find a .msi file.
  • Try executing the .msi file by providing the valid inputs.
  • Go to inetpub & check your website with the given alias & app pool exists or not.
  • If exists, try executing the website to see all the files are working or not.
By writing some powershell script on postbuild events,
  1. Open the website- Properties, Build Events- On postbuild script, Before that try to create a batch file which contains the info like following CD %1msbuild /t:Harvest;WIX %2here%1 is source file location, %2 is file name.
  2. Try to execute this batch file from Postbuild script.  
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe" /t:Build;PublishWebsite;harvest;wix;DeleteTmpFiles D:\iPSL\IMP\WIX\WixWebAutomated\WixWebInstaller\setup.build


So, when ever you build the website, it will automatically generate the .msi file in perticular folder. so you can share that .msi file to the testing team, they can directly double hit and install the binaries which automatically creates a website in the IIS server with new app pool.

Thursday, April 13, 2017

Useful Actions of System.Diagnostics

The namespace System.Diagnostics provides a set of attributes and classes to interact with the system process, event managers, performance counts etc. This namespace can help us too in debugging jobs.

Let’s review the useful actions inside System.Diagnostics namespace.

DebuggerDisplay Attribute

DebuggerDisplay attribute drives the string format with debug screen, which shows the value of: class, properties or fields.

For this same task, it is best known override ToString method, but use DebbugerDisplay attribute is a better choice, because this does not modify the data structure as it only interacts with Visual Studio debbuger screen. Override ToString method for only this purpose can give problems because many actions in .NET takes this value for default, for example bindings in WPF.

This attribute supports delegates, properties, fields and assamblies.

Example

[System.Diagnostics.DebuggerDisplay("{ID} - {Model}- {Manufacturer} - {ProductionDate}")]
public class Car
{
    public int      ID             { get; set; }
    public string   Model        { get; set; }
    public string   Manufacturer   { get; set; }
    public DateTime ProductionDate { get; set; }
}  


DebuggerHidden Attribute

DebuggerHidden attribute prevents the compiler from stopping in constructors, methods, properties and indexers declarations.

In mentioning this later, my comment might sound lightweight, but in the practice, this can save time push key F11 in debugging.

Example 

[System.Diagnostics.DebuggerHidden]
public static List<Car> GetData()
{
    var result = new List<Car>()
    {
        new Car{ ID = 1, Manufacturer = "Ford",   Model = "Mustang", ProductionDate = DateTime.Today },
        new Car{ ID = 2, Manufacturer = "Nissan", Model = "Micra"  , ProductionDate = DateTime.Today }
    };
 
    return result;
}  

Debugger.Launch

Occasionally, we can’t debug the code of a library, Service etc. because it is not accessible or we can’t add project to our solution. In this case, we can use the Debugger.Launch() method and Visual Studio opens a debug Window and we can debug its code.

When executed, the line Systen.Diagnostics.Debbuger.Launch() opens a MessageBox with the instance of Visual Studio Debugger Options.

In this window, we can choose, if we open a new stance of Visual Studio (all versions) or if we re-use an existing instance.

We can debug the code, as shown below.


Conditional Attribute

Conditional attribute allows us to indicate a condition to the methods so that the compiler executes or does not execute its content.

We can use it with the precompiler sentences as DEBUG.

static void Main(string[] args)
{
 
    DebugMethod();
 
 
    Console.Read();
}
 
[System.Diagnostics.Conditional("DEBUG")]
public static void DebugMethod()
{
    Console.WriteLine("Execute Debug Method");
}  
It will only run if the solutions configurations are debugged.

The condition doesn’t exist for RELEASE, therefore we will use a define Directives.

Define Directives is another way to use System.Diagnostics.Conditional,

#define RELEASE_MODE
 
using System;
namespace SystemDiagnosticsUsefulActions
{
    class Program
    {
        static void Main(string[] args)
        {
            ReleaseMethod();
 
            Console.Read();
        }
 
        [System.Diagnostics.Conditional("RELEASE_MODE")]
        public static void ReleaseMethod()
        {
            Console.WriteLine("Execute Release Method");
        }
 
    }
 
}  

Encrypt/Decrypt the App.Config

Program.cs using System; using System.Diagnostics; using System.IO; namespace EncryptAppConfig {     internal class Program     {         pr...