<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Traversed Paths</title>
	<atom:link href="http://blog.zingersaga.net/Index.php?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://blog.zingersaga.net</link>
	<description>Share of Dinesh&#039;s technical experiences</description>
	<lastBuildDate>Mon, 01 Aug 2011 17:03:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<atom:link rel="next" href="http://blog.zingersaga.net/Index.php?feed=rss2&amp;page=2" />

		<item>
		<title>Automated compilation of Visual Studio Projects through C# using MSBuild</title>
		<link>http://blog.zingersaga.net/?p=117</link>
		<comments>http://blog.zingersaga.net/?p=117#comments</comments>
		<pubDate>Wed, 19 Jan 2011 12:00:17 +0000</pubDate>
		<dc:creator>Dinesh</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.zingersaga.net/?p=117</guid>
		<description><![CDATA[<p><strong>Automated compilation of Visual Studio project</strong> 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.</p>
<p>You need to make a reference to <strong>Microsoft.Build.Engine. </strong>We also need a <strong>file logger class </strong>to record the outputs thrown by the MSBuild while compiling.</p>
<p><strong><span style="color: #0000ff;">Output of the C# program</span></strong> while compiling solution <em>“Web1”</em>,</p>
<p><a href="http://blog.zingersaga.net/wp-content/uploads/2011/01/errors_listing1.jpg"><img class="aligncenter size-full wp-image-120" title="errors_listing" src="http://blog.zingersaga.net/wp-content/uploads/2011/01/errors_listing1.jpg" alt="" width="669" height="338" /></a></p>
<p><strong><span style="color: #0000ff;">Actual error listing made by Visual Studio</span></strong> on the while compiling solution <em>“Web1”</em>,</p>
<p><a href="http://blog.zingersaga.net/wp-content/uploads/2011/01/vs_errors_listing1.jpg"><img class="aligncenter size-full wp-image-121" title="vs_errors_listing" src="http://blog.zingersaga.net/wp-content/uploads/2011/01/vs_errors_listing1.jpg" alt="" width="537" height="192" /></a></p>
<p>Here just shown the output first, don&#8217;t get confused. Find the code below,</p>
<p><strong><span style="color: #0000ff;">C# code for MSBuild:</span></strong></p>
<p>The solution builder class which is the core of this application is as follows,</p>
<blockquote><p>using Microsoft.Build.BuildEngine;<br />
using Microsoft.Build.Framework;<br />
using Microsoft.Build.Utilities;public class SolutionBuilder<br />
{<br />
BasicFileLogger b;<br />
public SolutionBuilder() { }</p>
<p>[STAThread]<br />
public string Compile(string solution_name,string logfile)<br />
{<br />
b = new BasicFileLogger();</p>
<p>b.Parameters = logfile;</p>
<p>b.register();</p>
<p>Microsoft.Build.BuildEngine.Engine.GlobalEngine.BuildEnabled = true;</p>
<p>Project p = new Project (Microsoft.Build.BuildEngine.Engine.GlobalEngine);</p>
<p>p.BuildEnabled = true;</p>
<p>p.Load(solution_name);</p>
<p>p.Build();</p>
<p>string output = b.getLogoutput();</p>
<p>output += &#8220;\n\t&#8221; + b.Warningcount + &#8221; Warnings. &#8220;;<br />
output += &#8220;\n\t&#8221; + b.Errorcount + &#8221; Errors. &#8220;;</p>
<p>b.Shutdown();</p>
<p>return output;<br />
}<br />
}</p></blockquote>
<p>The above class is used and compilation is initiated by the following code,</p>
<blockquote><p>static void Main(string[] args)<br />
{<br />
SolutionBuilder builder = new SolutionBuilder();string output = builder.Compile(@&#8221;G:\Codes\Testing\Testing2\web1.sln&#8221;, @&#8221;G:\Codes\Testing\Testing2\build_log.txt&#8221;);</p>
<p>Console.WriteLine(output);</p>
<p>Console.ReadKey();</p>
<p>}</p></blockquote>
<p><strong><span style="color: #0000ff;">About the code:</span> </strong><br />
Apart from these two codes, one more to be noticed is <strong>“BasicFileLogger” class</strong> which is used for the logging operations. This code is available in MSDN. You can also download from here: <a href="http://blog.zingersaga.net/wp-content/uploads/2011/01/BasicFileLogger.cs_.txt">BasicFileLogger.cs</a></p>
<p>This code worked for the <strong>properly created solutions</strong>. You can refer the way my previous post,  <a href="http://blog.zingersaga.net/?p=80"> creating a blank solution</a>. It is built and compiled using Microsoft Visual C# 2008. It works successfully in compiling a Visual Studio solutions.</p>
<p>I hope this would be helpful to build a system to build .NET projects.</p>
]]></description>
			<content:encoded><![CDATA[<p><strong>Automated compilation of Visual Studio project</strong> 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.</p>
<p>You need to make a reference to <strong>Microsoft.Build.Engine. </strong>We also need a <strong>file logger class </strong>to record the outputs thrown by the MSBuild while compiling.</p>
<p><strong><span style="color: #0000ff;">Output of the C# program</span></strong> while compiling solution <em>“Web1”</em>,</p>
<p><a href="http://blog.zingersaga.net/wp-content/uploads/2011/01/errors_listing1.jpg"><img class="aligncenter size-full wp-image-120" title="errors_listing" src="http://blog.zingersaga.net/wp-content/uploads/2011/01/errors_listing1.jpg" alt="" width="669" height="338" /></a></p>
<p><strong><span style="color: #0000ff;">Actual error listing made by Visual Studio</span></strong> on the while compiling solution <em>“Web1”</em>,</p>
<p><a href="http://blog.zingersaga.net/wp-content/uploads/2011/01/vs_errors_listing1.jpg"><img class="aligncenter size-full wp-image-121" title="vs_errors_listing" src="http://blog.zingersaga.net/wp-content/uploads/2011/01/vs_errors_listing1.jpg" alt="" width="537" height="192" /></a></p>
<p>Here just shown the output first, don&#8217;t get confused. Find the code below,</p>
<p><strong><span style="color: #0000ff;">C# code for MSBuild:</span></strong></p>
<p>The solution builder class which is the core of this application is as follows,</p>
<blockquote><p>using Microsoft.Build.BuildEngine;<br />
using Microsoft.Build.Framework;<br />
using Microsoft.Build.Utilities;public class SolutionBuilder<br />
{<br />
BasicFileLogger b;<br />
public SolutionBuilder() { }</p>
<p>[STAThread]<br />
public string Compile(string solution_name,string logfile)<br />
{<br />
b = new BasicFileLogger();</p>
<p>b.Parameters = logfile;</p>
<p>b.register();</p>
<p>Microsoft.Build.BuildEngine.Engine.GlobalEngine.BuildEnabled = true;</p>
<p>Project p = new Project (Microsoft.Build.BuildEngine.Engine.GlobalEngine);</p>
<p>p.BuildEnabled = true;</p>
<p>p.Load(solution_name);</p>
<p>p.Build();</p>
<p>string output = b.getLogoutput();</p>
<p>output += &#8220;\n\t&#8221; + b.Warningcount + &#8221; Warnings. &#8220;;<br />
output += &#8220;\n\t&#8221; + b.Errorcount + &#8221; Errors. &#8220;;</p>
<p>b.Shutdown();</p>
<p>return output;<br />
}<br />
}</p></blockquote>
<p>The above class is used and compilation is initiated by the following code,</p>
<blockquote><p>static void Main(string[] args)<br />
{<br />
SolutionBuilder builder = new SolutionBuilder();string output = builder.Compile(@&#8221;G:\Codes\Testing\Testing2\web1.sln&#8221;, @&#8221;G:\Codes\Testing\Testing2\build_log.txt&#8221;);</p>
<p>Console.WriteLine(output);</p>
<p>Console.ReadKey();</p>
<p>}</p></blockquote>
<p><strong><span style="color: #0000ff;">About the code:</span> </strong><br />
Apart from these two codes, one more to be noticed is <strong>“BasicFileLogger” class</strong> which is used for the logging operations. This code is available in MSDN. You can also download from here: <a href="http://blog.zingersaga.net/wp-content/uploads/2011/01/BasicFileLogger.cs_.txt">BasicFileLogger.cs</a></p>
<p>This code worked for the <strong>properly created solutions</strong>. You can refer the way my previous post,  <a href="http://blog.zingersaga.net/?p=80"> creating a blank solution</a>. It is built and compiled using Microsoft Visual C# 2008. It works successfully in compiling a Visual Studio solutions.</p>
<p>I hope this would be helpful to build a system to build .NET projects.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.zingersaga.net/?feed=rss2&#038;p=117</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Test</title>
		<link>http://blog.zingersaga.net/?p=104</link>
		<comments>http://blog.zingersaga.net/?p=104#comments</comments>
		<pubDate>Mon, 12 Jul 2010 22:17:11 +0000</pubDate>
		<dc:creator>Dinesh</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.zingersaga.net/blogging/wordpress/?p=104</guid>
		<description><![CDATA[<p>testing my component waste fellow I am to test this software further in this field man.. Please let me go<br />
[FLOWPLAYER=http://click2refer.com/rant%20rule.swf,200,400]</p>
]]></description>
			<content:encoded><![CDATA[<p>testing my component waste fellow I am to test this software further in this field man.. Please let me go<br />
[FLOWPLAYER=http://click2refer.com/rant%20rule.swf,200,400]</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.zingersaga.net/?feed=rss2&#038;p=104</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using MSBuild for automated build of .NET Projects</title>
		<link>http://blog.zingersaga.net/?p=80</link>
		<comments>http://blog.zingersaga.net/?p=80#comments</comments>
		<pubDate>Sun, 02 May 2010 20:20:03 +0000</pubDate>
		<dc:creator>dinesh</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET solution]]></category>
		<category><![CDATA[ASP.NET application]]></category>
		<category><![CDATA[Automated compilation]]></category>
		<category><![CDATA[MSBuild]]></category>
		<category><![CDATA[MSBuild Failure]]></category>
		<category><![CDATA[Portable solution]]></category>
		<category><![CDATA[Release management]]></category>
		<category><![CDATA[Visual studio project]]></category>

		<guid isPermaLink="false">http://www.zingersaga.net/blogging/wordpress/?p=80</guid>
		<description><![CDATA[<h3>Something about my project</h3>
<p>My final year project is <strong><span style="color: #800000;">“Release management application”</span></strong>.  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 <span style="color: #800000;">automated compilation process</span>. 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.</p>
<h3>MSBuild to compile .NET projects</h3>
<p>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<span style="color: #800000;"> “3-tier application architecture”</span>. 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.</p>
<h3>MSBuild failed for some solutions</h3>
<p>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.</p>
<p>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,</p>
<p><span style="color: #0000ff;"><br />
</span></p>
<blockquote><p><span style="color: #0000ff;">Debug.AspNetCompiler.VirtualPath = &#8220;/Release_management&#8221;</span></p>
<p><span style="color: #0000ff;">Debug.AspNetCompiler.PhysicalPath = <span style="color: #ff0000;">&#8220;E:\tdb\Release_management\&#8221;</span></span></p>
<p><span style="color: #0000ff;">Debug.AspNetCompiler.TargetPath = &#8220;PrecompiledWeb\Release_management\&#8221;</span></p>
<p><span style="color: #0000ff;"><br />
</span></p>
<p><span style="color: #0000ff;">Release.AspNetCompiler.VirtualPath = &#8220;/Release_management&#8221;</span></p>
<p><span style="color: #0000ff;">Release.AspNetCompiler.PhysicalPath = <span style="color: #ff0000;">&#8220;E:\tdb\Release_management\&#8221;</span></span></p>
<p><span style="color: #0000ff;">Release.AspNetCompiler.TargetPath = &#8220;PrecompiledWeb\Release_management\&#8221;</span></p></blockquote>
<p>The physical path is set statically as “E:\tdb\Release_management”, it will lead to mismatch and build process will ultimately fail when we compile in a different machine.</p>
<h3>Starting with a blank solution is the key</h3>
<p>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; <em><span style="color: #800000;"><strong>this is the right way of creating a new visual studio solution</strong></span></em>.</p>
<blockquote>
<p style="padding-left: 30px;">When you click <em><strong><span style="color: #800000;">File -&gt; New Project -&gt; Other Project Types -&gt; Visual Studio Solutions -&gt; Blank Solution (under “Visual Studio installed templates”)</span>,</strong></em> you will get the following window.</p>
<div class="mceTemp mceIEcenter">
<dl>
<dt><a rel="attachment wp-att-81" href="http://blog.zingersaga.net/?attachment_id=81"><img class="size-full wp-image-81" src="http://www.zingersaga.net/blogging/wordpress/wp-content/uploads/2010/05/solution-creation.jpg" alt="Image of Visual studio blank solution creation window" width="684" height="477" /></a></dt>
</dl>
</div>
</blockquote>
<p style="text-align: justify; padding-left: 30px;">
<p style="text-align: justify; padding-left: 30px;"><em>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. </em></p>
<blockquote>
<p style="text-align: justify; padding-left: 30px;"><strong>You can find <a href="http://blog.zingersaga.net/?p=117">Sample C# code </a> here to build .NET projects.</strong></p>
</blockquote>
<p style="text-align: justify; padding-left: 30px;"><span style="color: #800000;">I am thankful to my guide<strong> Guru</strong> sir for his guidance.</span><em><br />
</em></p>
<p style="text-align: justify; padding-left: 30px;"><em><br />
</em></p>
<p style="text-align: justify; padding-left: 30px;">
<p style="text-align: justify; padding-left: 30px;"><em><br />
</em></p>
]]></description>
			<content:encoded><![CDATA[<h3>Something about my project</h3>
<p>My final year project is <strong><span style="color: #800000;">“Release management application”</span></strong>.  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 <span style="color: #800000;">automated compilation process</span>. 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.</p>
<h3>MSBuild to compile .NET projects</h3>
<p>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<span style="color: #800000;"> “3-tier application architecture”</span>. 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.</p>
<h3>MSBuild failed for some solutions</h3>
<p>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.</p>
<p>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,</p>
<p><span style="color: #0000ff;"><br />
</span></p>
<blockquote><p><span style="color: #0000ff;">Debug.AspNetCompiler.VirtualPath = &#8220;/Release_management&#8221;</span></p>
<p><span style="color: #0000ff;">Debug.AspNetCompiler.PhysicalPath = <span style="color: #ff0000;">&#8220;E:\tdb\Release_management\&#8221;</span></span></p>
<p><span style="color: #0000ff;">Debug.AspNetCompiler.TargetPath = &#8220;PrecompiledWeb\Release_management\&#8221;</span></p>
<p><span style="color: #0000ff;"><br />
</span></p>
<p><span style="color: #0000ff;">Release.AspNetCompiler.VirtualPath = &#8220;/Release_management&#8221;</span></p>
<p><span style="color: #0000ff;">Release.AspNetCompiler.PhysicalPath = <span style="color: #ff0000;">&#8220;E:\tdb\Release_management\&#8221;</span></span></p>
<p><span style="color: #0000ff;">Release.AspNetCompiler.TargetPath = &#8220;PrecompiledWeb\Release_management\&#8221;</span></p></blockquote>
<p>The physical path is set statically as “E:\tdb\Release_management”, it will lead to mismatch and build process will ultimately fail when we compile in a different machine.</p>
<h3>Starting with a blank solution is the key</h3>
<p>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; <em><span style="color: #800000;"><strong>this is the right way of creating a new visual studio solution</strong></span></em>.</p>
<blockquote>
<p style="padding-left: 30px;">When you click <em><strong><span style="color: #800000;">File -&gt; New Project -&gt; Other Project Types -&gt; Visual Studio Solutions -&gt; Blank Solution (under “Visual Studio installed templates”)</span>,</strong></em> you will get the following window.</p>
<div class="mceTemp mceIEcenter">
<dl>
<dt><a rel="attachment wp-att-81" href="http://blog.zingersaga.net/?attachment_id=81"><img class="size-full wp-image-81" src="http://www.zingersaga.net/blogging/wordpress/wp-content/uploads/2010/05/solution-creation.jpg" alt="Image of Visual studio blank solution creation window" width="684" height="477" /></a></dt>
</dl>
</div>
</blockquote>
<p style="text-align: justify; padding-left: 30px;">
<p style="text-align: justify; padding-left: 30px;"><em>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. </em></p>
<blockquote>
<p style="text-align: justify; padding-left: 30px;"><strong>You can find <a href="http://blog.zingersaga.net/?p=117">Sample C# code </a> here to build .NET projects.</strong></p>
</blockquote>
<p style="text-align: justify; padding-left: 30px;"><span style="color: #800000;">I am thankful to my guide<strong> Guru</strong> sir for his guidance.</span><em><br />
</em></p>
<p style="text-align: justify; padding-left: 30px;"><em><br />
</em></p>
<p style="text-align: justify; padding-left: 30px;">
<p style="text-align: justify; padding-left: 30px;"><em><br />
</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.zingersaga.net/?feed=rss2&#038;p=80</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

