All about Click2Refer


 

Click2Refer Demo page

Automated compilation of Visual Studio Projects through C# using MSBuild


Automated compilation of Visual Studio project is a feature of many project management tools.  The same could be done easily through C# as well. We can use the MSBuild tool to accomplish this.

You need to make a reference to Microsoft.Build.Engine. We also need a file logger class to record the outputs thrown by the MSBuild while compiling.

Output of the C# program while compiling solution “Web1”,

Actual error listing made by Visual Studio on the while compiling solution “Web1”,

Here just shown the output first, don’t get confused. Find the code below,

C# code for MSBuild:

The solution builder class which is the core of this application is as follows,

using Microsoft.Build.BuildEngine;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;public class SolutionBuilder
{
BasicFileLogger b;
public SolutionBuilder() { }

[STAThread]
public string Compile(string solution_name,string logfile)
{
b = new BasicFileLogger();

b.Parameters = logfile;

b.register();

Microsoft.Build.BuildEngine.Engine.GlobalEngine.BuildEnabled = true;

Project p = new Project (Microsoft.Build.BuildEngine.Engine.GlobalEngine);

p.BuildEnabled = true;

p.Load(solution_name);

p.Build();

string output = b.getLogoutput();

output += “nt” + b.Warningcount + ” Warnings. “;
output += “nt” + b.Errorcount + ” Errors. “;

b.Shutdown();

return output;
}
}

The above class is used and compilation is initiated by the following code,

static void Main(string[] args)
{
SolutionBuilder builder = new SolutionBuilder();string output = builder.Compile(@”G:CodesTestingTesting2web1.sln”, @”G:CodesTestingTesting2build_log.txt”);

Console.WriteLine(output);

Console.ReadKey();

}

About the code:
Apart from these two codes, one more to be noticed is “BasicFileLogger” class which is used for the logging operations. This code is available in MSDN. You can also download from here:BasicFileLogger.cs

This code worked for the properly created solutions. You can refer the way my previous post, Creating a blank solution. It is built and compiled using Microsoft Visual C# 2008. It works successfully in compiling a Visual Studio solutions.

I hope this would be helpful to build a system to build .NET projects.

Using MSBuild for automated build of .NET Projects


Something about my project

My final year project is “Release management application”.  It makes the software release process easier for the software companies. The application is set to work for .NET and PHP projects.  One of the important module is that automated compilation process. This module will automatically compile the projects stored in VSS (Visual SourceSafe) to ensure no errors before making a release in that module. We won’t continue release process when there are errors.

MSBuild to compile .NET projects

The visual studio solution file usually will have an ASP.NET project and business layer and data access layer class libraries in majority of web based projects. People call it “3-tier application architecture”. Actually the solution file will be created in developer’s machine and saved in the VSS, the compilation process will occur at the release management application server which will be at a different location.

MSBuild failed for some solutions

It worked for me initially when we simply compiled a simple “Console application”, but with solution containing ASP.NET web application, it was unable to locate projects rightly and failed.

I found the flaw when I opened that solution file using notepad. ASP.NET applications use two paths, virtual and physical path, whereas the console application didn’t. The following lines give you an idea about them,


Debug.AspNetCompiler.VirtualPath = “/Release_management”

Debug.AspNetCompiler.PhysicalPath = “E:\tdb\Release_management”

Debug.AspNetCompiler.TargetPath = “PrecompiledWebRelease_management”


Release.AspNetCompiler.VirtualPath = “/Release_management”

Release.AspNetCompiler.PhysicalPath = “E:\tdb\Release_management”

Release.AspNetCompiler.TargetPath = “PrecompiledWebRelease_management”

The physical path is set statically as “E:tdbRelease_management”, it will lead to mismatch and build process will ultimately fail when we compile in a different machine.

Starting with a blank solution is the key

The cause of this problem is that, the way we created the solution file when we started coding phase of the project. When we start coding, we should make a blank solution and then proceed adding projects further; this is the right way of creating a new visual studio solution.

When you click File -> New Project -> Other Project Types -> Visual Studio Solutions -> Blank Solution (under “Visual Studio installed templates”), you will get the following window.

I finally compiled ASP.NET applications easily with projects created using above method, thereby completed the automated compilation process which is crucial for my project.

You can find Sample C# code here to build .NET projects.

I am thankful to my guide Guru sir for his guidance.



An encouraging article I read for “Programming success”.


Hi,

I  read from a web page titled “Teach Yourself Programming in Ten Years” at http://norvig.com/21-days.html

I just would like to share the excerpt from it which i wondered.. It says that to expertise in any field it takes ten years.

“Researchers (Bloom (1985), Bryan & Harter (1899), Hayes (1989), Simmon & Chase (1973)) have shown it takes about ten years to develop expertise in any of a wide variety of areas, including chess playing, music composition, telegraph operation, painting, piano playing, swimming, tennis, and research in neuropsychology and topology. The key is deliberative practice: not just doing it again and again, but challenging yourself with a task that is just beyond your current ability, trying it, analyzing your performance while and after doing it, and correcting any mistakes. Then repeat. And repeat again. There appear to be no real shortcuts: even Mozart, who was a musical prodigy at age 4, took 13 more years before he began to produce world-class music.”

The page also lists some receipe for programming success like (get interested, work on projects, work on others code  and so on ).

It will be useful for programmers like me..

Removing “sumanya,kanthi,lucky” virus – My solution.


Hi,  I would like to share something that I found. I was annoyed by the viruses in CCC in our college. We are always devastated by new viruses every few months.

The most annoying one is that “Sumanya, kanthi …“  virus. It had some different nature like when we close any one of such, it used to pop some more similar processes. I tried as many different ways and finally closed it by one way.

Removing virus from memory:

It’s been simple. These are the steps,

  1. Open  “Task Manager” ->  “Processes” tab. Just click on “Image name” to sort it out for easy operation.
  2. Now you could see some redundant group of processes with names like “k,.exe”, “s,.exe” and “winlg.exe”.
  3. Just choose any one process of each group (for ex: choose one of “k,.exe” file) and right click and press “End Process Tree”. Don’t bother about the newly spawned processes if it creates any further.
  4. Now repeat the above step for “s,.exe” and “winlg.exe”.
  5. It’s almost removed. Now you got to switch for “Applications” tab in your task manager. Just choose all those “sumanya, kanthi and lucky” file names and right click to put “End Task”.
  6. You have now removed that virus from memory.

:) :)

Cleaning the infected pen drive:

If you feel you are already infected by the virus in your pen drive, don’t worry we can get back our hidden files easily. Just use the following steps. Do these steps very carefully.

  1. Open command prompt and change to your pen drive.
  2. Just use this command “attrib –h –s –r /S /D”. This will make visible all hidden files in pen drive visible.  Now you can see your files back in pen drive.

If you are ready to remove viruses from your drive, just go for following steps, you are doing these steps at your own risk, I am not responsive for any of your mistakes.. Do it carefully.

Just open windows “Find” and choose pen drive directory.

  1. Put file name as “*.exe” and set file size as at most 320 KB. In most systems I noticed the size of that virus as 316 KB. In some systems it varied like 370 or 382 too. Adjust accordingly.
  2. Make sure you chosen the option to search hidden files and folders.
  3. Now you click search and see the results. Just sort out by size.
  4. You can notices the files of 316 KB. They are all viruses unless you know that that’s your program rather. Take care of that.
  5. You just choose all those virus files and delete them. Yes its over, Your pen drive is clean now !!!

Those viruses are just off and you can work safely guys.

Have  a nice day :)

Hello world!


Welcome to my first blog !!. I have setup my blog successfully.

I wanted to blog here to share what i am getting to know. I hope that would be useful to my folks and friends.

Today we have lots of information,  I can understand the value of information when that comes handy rather than it coming out of a search for long time, so comes this module in my website.

I invite you friend to comment and share.. :)