How to specify the path in the environment of a variable environment, so that you can compile with the command line C # code. I already have Visual Studio 2008 Express. I would like to compile through the command line to learn.

  • "Variable environment" =). - kirelagin

4 answers 4

You need csc.exe .

The problem is that this file is usually hidden in the depths of the Windows folder (for example, I found it in C:\Windows\Microsoft.NET\Framework\v4.0.30319 ). So better use VSVARS32 .

Command-line Building With csc.exe

    The C # compiler also has an API available in the .NET Framework. Used like this:

     using Microsoft.CSharp; using System.Resources; public void Compile(string[] resourceFiles, string[] references, string outputFileName) { var compiledResources = new List<string>(); foreach (string resourceFile in resourceFiles) { string resourceRoot = new FileInfo(outputFileName).Directory.FullName; using (ResXResourceReader reader = new ResXResourceReader(resourceFile)) { string outResPath = resourceRoot + "\\" + Path.GetFileNameWithoutExtension(resourceFile) + ".resources"; using (ResourceWriter rw = new ResourceWriter(outResPath)) { IDictionaryEnumerator ren = reader.GetEnumerator(); while (ren.MoveNext()) { rw.AddResource(ren.Key.ToString(), ren.Value.ToString()); } compiledResources.Add(outResPath); } } } CSharpCodeProvider codeProvider = new CSharpCodeProvider(); CompilerParameters parameters = new CompilerParameters(references.ToArray(), outputFileName); parameters.EmbeddedResources.AddRange(compiledResources.ToArray()); CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, sourceCodes); foreach (CompilerError error in results.Errors) { //speakOut(string.Format("Line:{0:d},Error:{1}\n", error.Line, error.ErrorText)); } } 

      “My computer” - properties. Windows XP - "advanced", Windows Vista / 7 - "Advanced system settings." Tab "Advanced" - "Environment Variables ..." Next in the "System Variables" look for the Path variable. In the end, append the path to the compiler through a semicolon (for example, C: WindowsMicrosoft.NETFrameworkv4.0.30319)

      • You can simply write the full path to csc on the command line - no path is required. Although, if you often have to compile this way, it can be convenient. - Qwertiy ♦

      You can compile a project with code using msbuild (not included in client profile 4.0, but included in all the others), separate files - using csc (it is everywhere) - look for them in the folder with the .net framework.

      http://bbs.vbstreets.ru/viewtopic.php?f=2&t=44609 - a bat-file for compiling VB.NET (using vbc), C # is done in a similar way.