title: Setup environment using batch file for DotNet Framework Version Command line for easy way around
body: <p>I have .net framework 4.0 (and older versions, i.e. multiple versions) installed, want to use the command line compiler for C# </p>
  
  <pre><code>C:\&gt;csc.exe
  </code></pre>
  
  <p>Now I found across few forums using the direct path I can use the compiler, also using batch file one can do that,</p>
  
  <p>I need to set environment variables <a href="http://msdn.microsoft.com/en-us/library/vstudio/1700bbwd.aspx" rel="nofollow noreferrer">LINK</a> but that is part of visual studio(if VS is installed then only it works) I want to use the compiler from the redistributable .net framework(using command line only) which is free to use and distribute. </p>
  
  <p>Do not want to install Visual Studio in the system where I run the code.</p>
  
  <p>my Current <code>CSC.exe</code> file location PATH is</p>
  
  <pre><code>C:\Windows\Microsoft.NET\Framework\v4.0.30319
  </code></pre>
  
  <p>This path and compiler file works fine but every time I have written like this and some times I have seen an error related to Library.</p>
  
  <pre><code>C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe sample.cs
  </code></pre>
  
  <p>How to avoid writing long path each time while testing the sample codes?</p>
  
  <p>Please provide best available alternate(Batch file or something)</p>
  
  <p>Edit 1: Setting Path:</p>
  
  <p>Paul's answer is works fine with simple program, But the issue with that is if there are any Library files used/added, were not found in this case.</p>
  
  <p>Note: Version is not a constraint actually, we may use any .net redistributable version. Just CSC.exe should accessible from any path without any issue(example library files used).</p>