<?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>TechiesWeb &#187; Deployment</title>
	<atom:link href="http://www.techiesweb.net/category/deployment/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.techiesweb.net</link>
	<description>Programming tips &#38; tricks,What went wrong while coding,Code snippets,ASP,ASP.NET,PHP,MySQL,SQL Server,jQuery,AJAX</description>
	<lastBuildDate>Tue, 22 Dec 2009 10:21:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Setting PATH while Installing an Application &#8211; Visual Studio 2005 Setup project</title>
		<link>http://www.techiesweb.net/2008/07/setting-path-while-installing-an-application-visual-studio-2005-setup-project/</link>
		<comments>http://www.techiesweb.net/2008/07/setting-path-while-installing-an-application-visual-studio-2005-setup-project/#comments</comments>
		<pubDate>Wed, 09 Jul 2008 14:10:38 +0000</pubDate>
		<dc:creator>Shyju</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[MicroSoft]]></category>
		<category><![CDATA[setup project]]></category>
		<category><![CDATA[Visual Studio setup project]]></category>

		<guid isPermaLink="false">http://techiesweb.wordpress.com/?p=14</guid>
		<description><![CDATA[Deployment in Visual studio,Running an exe while installing setup,Setting PATH variable while installing an application,Setting path variable in C#]]></description>
			<content:encoded><![CDATA[<p>A Small stuff to explain how to set the path variable for our executable&#8217;s Application folder.So that we can call the executable from anywhere in the PC ,(like invoking the notepad application from the PC,by command prompt).</p>
<p>Start&#8230;&#8230;????????</p>
<p>Create a Project for Your Actual requirement.Write code for the functionalities u want to run when the user run the executable on the machine.Once You finish it,You can add a deployment Setup project to this project.for this Go to File-&gt;Add-&gt;New Project.Then a Dialog box will appear and from there we can select the Other Project types-&gt;Setup wizard.This Project will be added to the Available Project and Hence a Solution will be created and both of the projects will be comes under the Solution.</p>
<p>I hope you guys know how to Go ahead with the deployment creation wizard.very simple.Only thing u need to do is clicking the proper NEXT buttons !</p>
<p><a href="http://techiesweb.files.wordpress.com/2008/07/solnxplr_withsetuppgm.gif"><img class="alignnone size-full wp-image-15" src="http://techiesweb.files.wordpress.com/2008/07/solnxplr_withsetuppgm.gif" alt="Solution Explorer with 2 projects" /></a></p>
<p>Now When u build the Projects,You will get the Installable stuff.You can find this in your project&#8217;s(Deployment Setup project) Debug directory.The file name will be having an .msi extension.</p>
<p><a href="http://techiesweb.files.wordpress.com/2008/07/explorer_projectsetupoutput.gif"><img class="alignnone size-full wp-image-16" src="http://techiesweb.files.wordpress.com/2008/07/explorer_projectsetupoutput.gif" alt="Project Setup output" /></a></p>
<p>You can run this installer program in your pc and it will install our Application in it.</p>
<p>If you go to the Application folder ,You can see the executable there.</p>
<p><a href="http://techiesweb.files.wordpress.com/2008/07/exe_in_prgmfiles.gif"><img class="alignnone size-full wp-image-17" src="http://techiesweb.files.wordpress.com/2008/07/exe_in_prgmfiles.gif" alt="exe in progrm files" /></a></p>
<p>You can double click on the exe file to run it.</p>
<p>we can run the program from Commandprompt too.But for that we have to traverse through  the folders using cd command.<br />
Now we are going to make some changes to an environment variable for running our new executable.There is an environment variable called &#8220;Path&#8221; ,Where we will map some folder locations where the system has to search for some executables when a call for  the exe comes.</p>
<p>for example,if we are typing notepad in command line, a new Notepad application will be launched.how it came ?Here comes the significance of &#8220;PATH&#8221;.The Full address of the notepad.exe has been mapped in the Path variable.so when the system get a call to the executable.It will look in to the Folders which are mapped in PATH.</p>
<p>Now we are going to Set the path for our exe in the system environment variable.<br />
For that we will create another DLL and this dll will be called when the User installs our application</p>
<p>So we can add another project to our existing Solution.<br />
File-&gt;Add-&gt;New Project<br />
The newly added project too comes under solution explorer.Here we will add code to Set the path varaible value(our new appliacation folder location).In this we have to put the following code</p>
<p>// CODEpublic void SetPathVariable()<br />
{<br />
string[] cmd_args = System.Environment.GetCommandLineArgs();<br />
AppendPathVariable(cmd_args[0]);<br />
}<br />
public void AppendPathVariable(string appPath)<br />
{<br />
try<br />
{</p>
<p>string loc = GetPathOnly(appPath);<br />
// System.Environment.SetEnvironmentVariable(&#8220;Path&#8221;, loc, EnvironmentVariableTarget.User);<br />
string Value = System.Environment.GetEnvironmentVariable(&#8220;Path&#8221;, EnvironmentVariableTarget.Machine);<br />
Value = Value + &#8220;;&#8221; + loc;<br />
System.Environment.SetEnvironmentVariable(&#8220;Path&#8221;, Value, EnvironmentVariableTarget.Machine);</p>
<p>}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(&#8220;Omnex CRM found an Error in Setting the Environment variable\n&#8221; + ex.ToString());<br />
}<br />
}</p>
<p>// Function to Return the URL exclude the Application(exe) name<br />
public string GetPathOnly(string url)<br />
{<br />
string outputStr = &#8220;&#8221;;<br />
string ipurl = url;<br />
char[] delimiter = { &#8216;\\&#8217; };<br />
string[] values = ipurl.Split(delimiter);<br />
for (int i = 0; i &lt; values.Length &#8211; 1; i++)<br />
{<br />
if (i == 0)<br />
{<br />
outputStr = values[i];<br />
}<br />
else<br />
{<br />
outputStr = outputStr + &#8220;\\&#8221; + values[i];<br />
}<br />
}<br />
return outputStr;<br />
}</p>
<p>private void Form1_Load(object sender, EventArgs e)<br />
{<br />
SetPathVariable();<br />
this.Close();<br />
}</p>
<p>//CODE ENDS</p>
<p>This part is over.from the code itself you would have understand what we are doing .<br />
In the Form_Load ,we are calling the method SetPAthVariable().Let us check what is</p>
<p>inside SetPathvaraiable.we are reading the commandline arguments and passing the first<br />
argument to another function called AppendPathVariable.Assume that the first argument<br />
is having the full path to the exe with the executable name.Inside AppendPathVariable,we are caling GetPathOnly() for removing the executable name from the entire path.After that we are fetching the current Path variable then appending the New Path to It.Using the static method SetEnvironmentVariable(),we are setting the newly created path.</p>
<p>Now we have to Pass the Commandline arguments to this Program.For that we will use the  custom action feature to our deployment Setup project<br />
(Select the Project View-&gt;Editor-&gt;Custom Action).</p>
<p><a href="http://techiesweb.files.wordpress.com/2008/07/addcustomaction.gif"><img class="alignnone size-full wp-image-18" src="http://techiesweb.files.wordpress.com/2008/07/addcustomaction.gif" alt="Add Custom Action to Deployment Project" /></a></p>
<p>There will be for options such as Install,Commit,Rollback,UnInstall<br />
Select Commit,Right click,Select Add custom action,Select the EXE where i have the code to set the path variable.</p>
<p><a href="http://techiesweb.files.wordpress.com/2008/07/cusomactiontoetup.gif"><img class="alignnone size-full wp-image-19" src="http://techiesweb.files.wordpress.com/2008/07/cusomactiontoetup.gif" alt="Add Custom Action" /></a><br />
Click OK<br />
Select the Newly added Exe from the list.Go to its properties,</p>
<p>Set the Installer class property to <strong><span style="color:#0000ff;">false</span></strong>.<br />
Set the value of the ARGUMENTS property to</p>
<p><strong><span style="color:#0000ff;">&#8220;[OriginalDatabase]&lt;&gt;[TARGETDIR]&lt;&gt;[ComputerName]&#8220;</span></strong></p>
<p><a href="http://techiesweb.files.wordpress.com/2008/07/customaction_proprties.gif"><img class="alignnone size-full wp-image-20" src="http://techiesweb.files.wordpress.com/2008/07/customaction_proprties.gif" alt="custom Action Properties" /></a></p>
<p>Thats all here.<br />
Then just build the Projects-Solution.Get the Latest msi files from the Debug folder of Deployment Setup project</p>
<p>Guys , try this .This was working for me.If you have any queries , Please let me know .Happy to help (with my little knowledge)&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techiesweb.net/2008/07/setting-path-while-installing-an-application-visual-studio-2005-setup-project/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
