public static void PreloadFromHtmlList(string filename) { if (versions.Count == 0) { if (File.Exists(filename)) { string[] lines = File.ReadAllLines(filename); CompilerVersion ver; for (int i = 0; i < lines.Length; i++) { int idx1 = lines[i].IndexOf("dmd.1."); int idx2 = lines[i].IndexOf("dmd.2."); if (idx1 > 0 || idx2 > 0) { ver = new CompilerVersion(); if (ver.FromHtml(lines[i])) { if (!versions.ContainsKey(ver.Version) || versions[ver.Version].SubVersion < ver.SubVersion) { versions[ver.Version] = ver; } } } } if (!DataFile.Exists && versions.Count == 2) { StringBuilder sb = new StringBuilder(); foreach (CompilerVersion v in versions.Values) sb.Append(v.ToString()).Append("\r\n"); File.WriteAllText(DataFile.FullName, sb.ToString()); DataFile.Refresh(); } } } }
public static CodeDomProvider CreateProvider(Language language, CompilerVersion version) { var providerOptions = GetProviderOptions(version); var provider = CodeDomProvider.CreateProvider(language.ToString(), providerOptions); return provider; }
public override void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework) { PortableTargetFramework newFx = newFramework as PortableTargetFramework; if (newFx != null) { // Convert to portable library Core.AnalyticsMonitorService.TrackFeature(GetType(), "ConvertToPortableLibrary"); var project = (CompilableProject)Project; lock (project.SyncRoot) { if (newVersion != null && GetAvailableCompilerVersions().Contains(newVersion)) { project.SetToolsVersion(newVersion.MSBuildVersion.Major + "." + newVersion.MSBuildVersion.Minor); } project.SetProperty(null, null, "TargetFrameworkProfile", newFx.TargetFrameworkProfile, PropertyStorageLocations.Base, true); project.SetProperty(null, null, "TargetFrameworkVersion", newFx.TargetFrameworkVersion, PropertyStorageLocations.Base, true); // Convert <Imports> project.PerformUpdateOnProjectFile( delegate { foreach (var import in project.MSBuildProjectFile.Imports) { if (import.Project.EndsWith(PortableLibraryProjectBehavior.NormalCSharpTargets, StringComparison.OrdinalIgnoreCase)) { import.Project = PortableLibraryProjectBehavior.PortableTargetsPath + PortableLibraryProjectBehavior.PortableCSharpTargets; break; } else if (import.Project.EndsWith(PortableLibraryProjectBehavior.NormalVBTargets, StringComparison.OrdinalIgnoreCase)) { import.Project = PortableLibraryProjectBehavior.PortableTargetsPath + PortableLibraryProjectBehavior.PortableVBTargets; break; } } }); // Remove references foreach (var referenceItem in project.GetItemsOfType(ItemType.Reference).ToArray()) { // get short assembly name: string assemblyName = referenceItem.Include; if (assemblyName.IndexOf(',') >= 0) { assemblyName = assemblyName.Substring(0, assemblyName.IndexOf(',')); } assemblyName += ","; if (KnownFrameworkAssemblies.FullAssemblyNames.Any(fullName => fullName.StartsWith(assemblyName, StringComparison.OrdinalIgnoreCase))) { // If it's a framework assembly, remove the reference // (portable libraries automatically reference all available framework assemblies) ProjectService.RemoveProjectItem(project, referenceItem); } } project.AddProjectType(ProjectTypeGuids.PortableLibrary); project.Save(); ProjectBrowserPad.RefreshViewAsync(); } } else { base.UpgradeProject(newVersion, newFramework); } }
public virtual void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework) { if (!IsReadOnly) { GetOrCreateBehavior().UpgradeProject(newVersion, newFramework); } }
public virtual void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework) { if (this.next != null) { next.UpgradeProject(newVersion, newFramework); } }
public override void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework) { if (!Project.ReadOnly) { lock (Project.SyncRoot) { TargetFramework oldFramework = Project.CurrentTargetFramework; if (newVersion != null && GetAvailableCompilerVersions().Contains(newVersion)) { Project.SetToolsVersion(newVersion.MSBuildVersion.Major + "." + newVersion.MSBuildVersion.Minor); } if (newFramework != null) { UpdateAppConfig(newFramework); ClientProfileTargetFramework clientProfile = newFramework as ClientProfileTargetFramework; if (clientProfile != null) { newFramework = clientProfile.FullFramework; ((MSBuildBasedProject)Project).SetProperty(null, null, "TargetFrameworkProfile", "Client", PropertyStorageLocations.Base, true); } else { ((MSBuildBasedProject)Project).SetProperty(null, null, "TargetFrameworkProfile", "", PropertyStorageLocations.Base, true); } ((MSBuildBasedProject)Project).SetProperty(null, null, "TargetFrameworkVersion", newFramework.Name, PropertyStorageLocations.Base, true); if (oldFramework is ClientProfileTargetFramework) { oldFramework = ((ClientProfileTargetFramework)oldFramework).FullFramework; } if (oldFramework != null && !oldFramework.IsBasedOn(TargetFramework.Net35) && newFramework.IsBasedOn(TargetFramework.Net35)) { AddDotnet35References(); } else if (oldFramework != null && oldFramework.IsBasedOn(TargetFramework.Net35) && !newFramework.IsBasedOn(TargetFramework.Net35)) { RemoveDotnet35References(); } if (oldFramework != null && !oldFramework.IsBasedOn(TargetFramework.Net40) && newFramework.IsBasedOn(TargetFramework.Net40)) { AddDotnet40References(); } else if (oldFramework != null && oldFramework.IsBasedOn(TargetFramework.Net40) && !newFramework.IsBasedOn(TargetFramework.Net40)) { RemoveDotnet40References(); } } AddOrRemoveExtensions(); Project.Save(); //TODO: Uncomment // ResXConverter.UpdateResourceFiles(Project); } } }
public static Dictionary<string, string> GetProviderOptions(CompilerVersion version) { Dictionary<string, string> providerOptions = new Dictionary<string, string>(); var str = GetCompilerVersion(version); if (str != null) providerOptions.Add("CompilerVersion", str); return providerOptions; }
private static Process CreateCompilerProcess(CompilerVersion version, string unityEditorDataDir, string responseFile) { string processPath; string processArguments; var systemDllPath = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/System.dll"); var systemCoreDllPath = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/System.Core.dll"); var systemXmlDllPath = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/System.Xml.dll"); switch (version) { case CompilerVersion.Version3: processPath = Path.Combine(unityEditorDataDir, @"Mono/bin/mono.exe"); var compilerPath = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/gmcs.exe"); processArguments = $"\"{compilerPath}\" {responseFile}"; break; case CompilerVersion.Version5: processPath = Path.Combine(unityEditorDataDir, @"MonoBleedingEdge/lib/mono/4.5/mcs.exe"); processArguments = $"-sdk:2 -langversion:Future -r:\"{systemCoreDllPath}\" {responseFile}"; break; case CompilerVersion.Version6Mono: processPath = Path.Combine(Directory.GetCurrentDirectory(), "mcs.exe"); processArguments = $"-sdk:2 -r:\"{systemCoreDllPath}\" {responseFile}"; break; case CompilerVersion.Version6Microsoft: processPath = Path.Combine(Directory.GetCurrentDirectory(), @"Roslyn/csc.exe"); var mscorlib = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/mscorlib.dll"); processArguments = $"-nostdlib+ -noconfig -r:\"{mscorlib}\" -r:\"{systemDllPath}\" -r:\"{systemCoreDllPath}\" -r:\"{systemXmlDllPath}\" {responseFile}"; break; default: throw new ArgumentOutOfRangeException(nameof(version), version, null); } var process = new Process { StartInfo = { FileName = processPath, Arguments = processArguments, RedirectStandardError = true, RedirectStandardOutput = true, UseShellExecute = false } }; process.OutputDataReceived += Process_OutputDataReceived; process.ErrorDataReceived += Process_ErrorDataReceived; return(process); }
public virtual void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework) { if (!this.ReadOnly) { lock (SyncRoot) { TargetFramework oldFramework = this.CurrentTargetFramework; if (newVersion != null && GetAvailableCompilerVersions().Contains(newVersion)) { SetToolsVersion(newVersion.MSBuildVersion.Major + "." + newVersion.MSBuildVersion.Minor); } if (newFramework != null) { UpdateAppConfig(newFramework); ClientProfileTargetFramework clientProfile = newFramework as ClientProfileTargetFramework; if (clientProfile != null) { newFramework = clientProfile.FullFramework; SetProperty(null, null, "TargetFrameworkProfile", "Client", PropertyStorageLocations.Base, true); } else { SetProperty(null, null, "TargetFrameworkProfile", "", PropertyStorageLocations.Base, true); } SetProperty(null, null, "TargetFrameworkVersion", newFramework.Name, PropertyStorageLocations.Base, true); if (oldFramework is ClientProfileTargetFramework) { oldFramework = ((ClientProfileTargetFramework)oldFramework).FullFramework; } if (oldFramework != null && !oldFramework.IsBasedOn(TargetFramework.Net35) && newFramework.IsBasedOn(TargetFramework.Net35)) { AddDotnet35References(); } else if (oldFramework != null && oldFramework.IsBasedOn(TargetFramework.Net35) && !newFramework.IsBasedOn(TargetFramework.Net35)) { RemoveDotnet35References(); } if (oldFramework != null && !oldFramework.IsBasedOn(TargetFramework.Net40) && newFramework.IsBasedOn(TargetFramework.Net40)) { AddDotnet40References(); } else if (oldFramework != null && oldFramework.IsBasedOn(TargetFramework.Net40) && !newFramework.IsBasedOn(TargetFramework.Net40)) { RemoveDotnet40References(); } } AddOrRemoveExtensions(); Save(); } } }
CompileFromFile( String InSourcePath, ExecutableType InExecType, GenerateAssemblyIn InGenerateIn, CompilerVersion CompilerVersion) { List <string> addnReferencedAssemblies = new List <string>(); AcCompilerResults results = Compile_Actual( InSourcePath, null, InExecType, InGenerateIn, addnReferencedAssemblies, CompilerVersion); return(results); }
CompileFromSource( string InSourceLines, ExecutableType InExecType, GenerateAssemblyIn InGenerateIn, List <string> InAddnReferencedAssemblies, CompilerVersion CompilerVersion) { AcCompilerResults results = Compile_Actual( null, InSourceLines, InExecType, InGenerateIn, InAddnReferencedAssemblies, CompilerVersion); return(results); }
public static string ToCodeDomString(this CompilerVersion CompilerVersion) { switch (CompilerVersion) { case Enums.CompilerVersion.v35: return("v3.5"); case Enums.CompilerVersion.v40: return("v4.0"); default: throw new ApplicationException("unsupported CompilerVersion " + CompilerVersion.ToString()); } }
public override void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework) { var project = (CompilableProject)Project; var newFx = newFramework as PortableTargetFramework; if (newFramework != null && newFx == null) { // convert to normal .NET project (not portable) SD.AnalyticsMonitor.TrackFeature(GetType(), "DowngradePortableLibrary"); project.PerformUpdateOnProjectFile( delegate { foreach (var import in project.MSBuildProjectFile.Imports) { if (import.Project.EndsWith(PortableCSharpTargets, StringComparison.OrdinalIgnoreCase)) { import.Project = NormalTargetsPath + NormalCSharpTargets; break; } else if (import.Project.EndsWith(PortableVBTargets, StringComparison.OrdinalIgnoreCase)) { import.Project = NormalTargetsPath + NormalVBTargets; break; } } }); project.RemoveProjectType(ProjectTypeGuids.PortableLibrary); AddReferenceIfNotExists("System"); AddReferenceIfNotExists("System.Xml"); if (newFramework.Version >= Versions.V3_5) { AddReferenceIfNotExists("System.Core"); } base.UpgradeProject(newVersion, newFramework); return; } lock (project.SyncRoot) { if (newVersion != null && GetAvailableCompilerVersions().Contains(newVersion)) { project.ToolsVersion = newVersion.MSBuildVersion.Major + "." + newVersion.MSBuildVersion.Minor; } if (newFx != null) { project.SetProperty(null, null, "TargetFrameworkProfile", newFx.TargetFrameworkProfile, PropertyStorageLocations.Base, true); project.SetProperty(null, null, "TargetFrameworkVersion", newFx.TargetFrameworkVersion, PropertyStorageLocations.Base, true); } project.Save(); ProjectBrowserPad.RefreshViewAsync(); } }
public override void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework) { // PortableTargetFramework newFx = newFramework as PortableTargetFramework; // if (newFx != null) { // // Convert to portable library // SD.AnalyticsMonitor.TrackFeature(GetType(), "ConvertToPortableLibrary"); // var project = (CompilableProject)Project; // lock (project.SyncRoot) { // var oldTargetFramework = project.CurrentTargetFramework; // if (newVersion != null && GetAvailableCompilerVersions().Contains(newVersion)) { // project.ToolsVersion = newVersion.MSBuildVersion.Major + "." + newVersion.MSBuildVersion.Minor; // } // project.SetProperty(null, null, "TargetFrameworkProfile", newFx.TargetFrameworkProfile, PropertyStorageLocations.Base, true); // project.SetProperty(null, null, "TargetFrameworkVersion", newFx.TargetFrameworkVersion, PropertyStorageLocations.Base, true); // // Convert <Imports> // project.PerformUpdateOnProjectFile( // delegate { // foreach (var import in project.MSBuildProjectFile.Imports) { // if (import.Project.EndsWith(PortableLibraryProjectBehavior.NormalCSharpTargets, StringComparison.OrdinalIgnoreCase)) { // import.Project = PortableLibraryProjectBehavior.PortableTargetsPath + PortableLibraryProjectBehavior.PortableCSharpTargets; // break; // } else if (import.Project.EndsWith(PortableLibraryProjectBehavior.NormalVBTargets, StringComparison.OrdinalIgnoreCase)) { // import.Project = PortableLibraryProjectBehavior.PortableTargetsPath + PortableLibraryProjectBehavior.PortableVBTargets; // break; // } // } // }); // // Remove references // foreach (var referenceItem in project.GetItemsOfType(ItemType.Reference).ToArray()) { // // get short assembly name: // string assemblyName = referenceItem.Include; // if (assemblyName.IndexOf(',') >= 0) // assemblyName = assemblyName.Substring(0, assemblyName.IndexOf(',')); // if (oldTargetFramework.ReferenceAssemblies.Any(fullName => string.Equals(fullName.ShortName, assemblyName, StringComparison.OrdinalIgnoreCase))) { // // If it's a framework assembly, remove the reference // // (portable libraries automatically reference all available framework assemblies) // ProjectService.RemoveProjectItem(project, referenceItem); // } // } // project.AddProjectType(ProjectTypeGuids.PortableLibrary); // project.Save(); // ProjectBrowserPad.RefreshViewAsync(); // } // } else { // base.UpgradeProject(newVersion, newFramework); // } }
public static string GetCompilerVersion(CompilerVersion version) { // attach to enum via description attribute instead... ? switch (version) { case CompilerVersion.v20: return "v2.0"; case CompilerVersion.v30: return "v3.0"; case CompilerVersion.v35: return "v3.5"; case CompilerVersion.v40: return "v4.0"; default: return null; } }
public override void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework) { if (!Project.IsReadOnly) { lock (Project.SyncRoot) { TargetFramework oldFramework = Project.CurrentTargetFramework; if (newVersion != null && GetAvailableCompilerVersions().Contains(newVersion)) { Project.ToolsVersion = newVersion.MSBuildVersion.Major + "." + newVersion.MSBuildVersion.Minor; } if (newFramework != null) { UpdateAppConfig(newFramework); ((MSBuildBasedProject)Project).SetProperty(null, null, "TargetFrameworkVersion", newFramework.TargetFrameworkVersion, PropertyStorageLocations.Base, true); ((MSBuildBasedProject)Project).SetProperty(null, null, "TargetFrameworkProfile", newFramework.TargetFrameworkProfile, PropertyStorageLocations.Base, true); if (oldFramework != null && oldFramework.Version < Versions.V3_5 && newFramework.Version >= Versions.V3_5) { AddDotnet35References(); } else if (oldFramework != null && oldFramework.Version >= Versions.V3_5 && newFramework.Version < Versions.V3_5) { RemoveDotnet35References(); } if (oldFramework != null && oldFramework.Version < Versions.V4_0 && newFramework.Version >= Versions.V4_0) { AddDotnet40References(); } else if (oldFramework != null && oldFramework.Version >= Versions.V4_0 && newFramework.Version < Versions.V4_0) { RemoveDotnet40References(); } } AddOrRemoveExtensions(); Project.Save(); ResXConverter.UpdateResourceFiles(Project); } } }
public static void PreloadFromHtmlList(string filename) { if (versions.Count == 0) { if (File.Exists(filename)) { string[] lines = File.ReadAllLines(filename); CompilerVersion ver; for (int i = 0; i < lines.Length; i++) { int idx1 = lines[i].IndexOf("dmd.1."); int idx2 = lines[i].IndexOf("dmd.2."); if (idx1 > 0 || idx2 > 0) { ver = new CompilerVersion(); if (ver.FromHtml(lines[i])) { if (!versions.ContainsKey(ver.Version) || versions[ver.Version].SubVersion < ver.SubVersion) { versions[ver.Version] = ver; } } } } if (!DataFile.Exists && versions.Count == 2) { StringBuilder sb = new StringBuilder(); foreach (CompilerVersion v in versions.Values) { sb.Append(v.ToString()).Append("\r\n"); } File.WriteAllText(DataFile.FullName, sb.ToString()); DataFile.Refresh(); } } } }
public virtual bool IsCompatibleWith(CompilerVersion compilerVersion) { return(MinimumMSBuildVersion <= compilerVersion.MSBuildVersion); }
private static Process CreateCompilerProcess(CompilerVersion version, string unityEditorDataDir, string responseFile) { string processPath; string processArguments; var systemDllPath = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/System.dll"); var systemCoreDllPath = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/System.Core.dll"); var systemXmlDllPath = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/System.Xml.dll"); switch (version) { case CompilerVersion.Version3: processPath = Path.Combine(unityEditorDataDir, @"Mono/bin/mono.exe"); var compilerPath = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/gmcs.exe"); processArguments = $"\"{compilerPath}\" {responseFile}"; break; case CompilerVersion.Version5: processPath = Path.Combine(unityEditorDataDir, @"MonoBleedingEdge/lib/mono/4.5/mcs.exe"); processArguments = $"-sdk:2 -langversion:Future -r:\"{systemCoreDllPath}\" {responseFile}"; break; case CompilerVersion.Version6Mono: processPath = Path.Combine(Directory.GetCurrentDirectory(), "mcs.exe"); processArguments = $"-sdk:2 -r:\"{systemCoreDllPath}\" {responseFile}"; break; case CompilerVersion.Version6Microsoft: processPath = Path.Combine(Directory.GetCurrentDirectory(), @"Roslyn/csc.exe"); var mscorlib = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/mscorlib.dll"); processArguments = $"-nostdlib+ -noconfig -r:\"{mscorlib}\" -r:\"{systemDllPath}\" -r:\"{systemCoreDllPath}\" -r:\"{systemXmlDllPath}\" {responseFile}"; break; default: throw new ArgumentOutOfRangeException(nameof(version), version, null); } var process = new Process { StartInfo = { FileName = processPath, Arguments = processArguments, RedirectStandardError = true, RedirectStandardOutput = true, UseShellExecute = false } }; process.OutputDataReceived += Process_OutputDataReceived; process.ErrorDataReceived += Process_ErrorDataReceived; return process; }
private static void GetDMDInfo() { if (versions.Count == 0) { bool hasError = false; if (DataFile.Exists) { string[] lines = File.ReadAllLines(DataFile.FullName); CompilerVersion ver; for (int i = 0; i < lines.Length; i++) { ver = new CompilerVersion(); if (ver.FromString(lines[i])) versions[ver.Version] = ver; else hasError = true; if (ver.HasError) hasError = true; } if (hasError) { DataFile.CopyTo(DataFile.FullName + "." + DateTime.Now.ToBinary() + ".log"); DataFile.Delete(); DataFile.Refresh(); } } if (!DataFile.Exists) { CompilerVersion ver1 = new CompilerVersion(), ver2 = new CompilerVersion(); int latestVer1 = 56, latestVer2 = 41, subVersion = 0; string url1 = "", url2 = ""; ver1.Version = 1; ver2.Version = 2; try { FtpWebRequest request = WebRequest.Create(DIGITAL_MARS_FTP) as FtpWebRequest; request.Method = WebRequestMethods.Ftp.ListDirectory; using (FtpWebResponse response = request.GetResponse() as FtpWebResponse) { /* * Enum all files in the ftp root. While scan through all of them, extract the version number, get the highest version number, and finally download the appropriate zip */ Console.WriteLine(response.StatusDescription); using (StreamReader reader = new StreamReader(response.GetResponseStream())) { while (!reader.EndOfStream) { string line = reader.ReadLine(); if (line.StartsWith("dmd.1.")) { string[] tokens = line.Split('.'); if (tokens.Length > 2 && !int.TryParse(tokens[2], out subVersion)) subVersion = latestVer1; if (tokens[tokens.Length - 1].Equals("zip", StringComparison.CurrentCultureIgnoreCase)) { if (latestVer1 < subVersion) { latestVer1 = subVersion; url1 = DIGITAL_MARS_HTTP + line; } } } else if (line.StartsWith("dmd.2.")) { string[] tokens = line.Split('.'); if (tokens.Length > 2 && !int.TryParse(tokens[2], out subVersion)) subVersion = latestVer2; if (tokens[tokens.Length - 1].Equals("zip", StringComparison.CurrentCultureIgnoreCase)) { if (latestVer2 < subVersion) { latestVer2 = subVersion; url2 = DIGITAL_MARS_HTTP + line; } } } } } response.Close(); } ver1.SubVersion = latestVer1; ver1.Url = url1; ver2.SubVersion = latestVer2; ver2.Url = url2; } catch (Exception ex) { ver1.Error = ERROR_PREFIX + ex.Message + Environment.NewLine + ex.StackTrace; ver2.Error = ERROR_PREFIX + ex.Message + Environment.NewLine + ex.StackTrace; } versions[1] = ver1; versions[2] = ver2; StringBuilder sb = new StringBuilder(); foreach (CompilerVersion ver in versions.Values) sb.Append(ver.ToString()).Append("\r\n"); File.WriteAllText(DataFile.FullName, sb.ToString()); } } }
public CSharpProjectCompiler(ILogger logger, IEnumerable<string> referencedAssemblies, CompilerVersion compilerVersion) { this.logger = logger; codeProvider = new CSharpCodeProvider(new Dictionary<string, string> {{"CompilerVersion", compilerVersion.CodePoviderName}}); this.referencedAssemblies = referencedAssemblies.Union(DefaultAssemblies); }
public override void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework) { throw new NotSupportedException(); }
Compile_Actual( string InSourcePath, string InSourceLines, ExecutableType InExecType, GenerateAssemblyIn InGenerateIn, List <string> InAddnReferencedAssemblies, CompilerVersion CompilerVersion ) { System.Reflection.Assembly assem = null; List <string> results = new List <string>(); CodeDomProvider provider = null; // Microsoft.CSharp.CSharpCodeProvider provider = null; string exeName = null; WipCompilerResults wipCr = new WipCompilerResults(); AcCompilerParameters cp = new AcCompilerParameters(); // compile from lines in a source array or source file if (InSourceLines != null) { cp.SourceLines = InSourceLines; } else { cp.SourceFileInfo = new FileInfo(InSourcePath); } // Select the code provider based on the input file extension. if (cp.SourceLines != null) { Dictionary <string, string> provOpts = new Dictionary <string, string>() { { "CompilerVersion", "v3.5" } }; provider = new Microsoft.CSharp.CSharpCodeProvider(provOpts); // provider = CodeDomProvider.CreateProvider("CSharp"); } else if (cp.SourceFileInfo.Extension.ToUpper(CultureInfo.InvariantCulture) == ".CS") { Dictionary <string, string> provOpts = new Dictionary <string, string>() { { "CompilerVersion", "v3.5" } }; provider = new Microsoft.CSharp.CSharpCodeProvider(provOpts); // provider = CodeDomProvider.CreateProvider("CSharp"); } else { results.Add("Source file must have a .cs or .vb extension"); } if (provider != null) { // type of executable: Windows, Console, ClassLibrary cp.ExecutableType = InExecType; cp.GenerateAssemblyIn = InGenerateIn; // setup name and path of the executable file to be created. if (cp.GenerateAssemblyIn == GenerateAssemblyIn.File) { if (cp.ExecutableType == ExecutableType.ClassLibrary) { exeName = AcFilePath.NameSansExtension(cp.SourceFileInfo.Name) + ".dll"; } else { exeName = AcFilePath.NameSansExtension(cp.SourceFileInfo.Name) + ".exe"; } string exePath = AcFilePath.AddTo(cp.SourceFileInfo.DirectoryName, exeName); cp.OutputAssembly = exePath; } // Set whether to treat all warnings as errors. cp.TreatWarningsAsErrors = false; cp.ReferencedAssemblies.Add("System.Dll"); cp.ReferencedAssemblies.Add("System.Drawing.Dll"); cp.ReferencedAssemblies.Add("System.Xml.Dll"); cp.ReferencedAssemblies.Add("System.Windows.Forms.dll"); // additional assemblies foreach (string s1 in InAddnReferencedAssemblies) { cp.ReferencedAssemblies.Add(s1); } // Invoke compilation of the source file. CompilerResults cr = null; if (cp.SourceLines != null) { cr = provider.CompileAssemblyFromSource(cp, cp.SourceLines); } else { cr = provider.CompileAssemblyFromFile(cp, cp.SourceFileInfo.FullName); } wipCr.SetCompilerResults(cr); wipCr.SetCompilerParameters(cp); // completion message results.Add(wipCr.CompletionMessage); if (wipCr.Errors.Count > 0) { foreach (CompilerError ce in wipCr.Errors) { results.Add(" " + ce.ToString()); } } // Return the results of the compilation. if (wipCr.Errors.Count > 0) { assem = null; } else { assem = wipCr.CompiledAssembly; } } return(wipCr); }
private static void GetDMDInfo() { if (versions.Count == 0) { bool hasError = false; if (DataFile.Exists) { string[] lines = File.ReadAllLines(DataFile.FullName); CompilerVersion ver; for (int i = 0; i < lines.Length; i++) { ver = new CompilerVersion(); if (ver.FromString(lines[i])) { versions[ver.Version] = ver; } else { hasError = true; } if (ver.HasError) { hasError = true; } } if (hasError) { DataFile.CopyTo(DataFile.FullName + "." + DateTime.Now.ToBinary() + ".log"); DataFile.Delete(); DataFile.Refresh(); } } if (!DataFile.Exists) { CompilerVersion ver1 = new CompilerVersion(), ver2 = new CompilerVersion(); int latestVer1 = 56, latestVer2 = 41, subVersion = 0; string url1 = "", url2 = ""; ver1.Version = 1; ver2.Version = 2; try { FtpWebRequest request = WebRequest.Create(DIGITAL_MARS_FTP) as FtpWebRequest; request.Method = WebRequestMethods.Ftp.ListDirectory; using (FtpWebResponse response = request.GetResponse() as FtpWebResponse) { /* * Enum all files in the ftp root. While scan through all of them, extract the version number, get the highest version number, and finally download the appropriate zip */ Console.WriteLine(response.StatusDescription); using (StreamReader reader = new StreamReader(response.GetResponseStream())) { while (!reader.EndOfStream) { string line = reader.ReadLine(); if (line.StartsWith("dmd.1.")) { string[] tokens = line.Split('.'); if (tokens.Length > 2 && !int.TryParse(tokens[2], out subVersion)) { subVersion = latestVer1; } if (tokens[tokens.Length - 1].Equals("zip", StringComparison.CurrentCultureIgnoreCase)) { if (latestVer1 < subVersion) { latestVer1 = subVersion; url1 = DIGITAL_MARS_HTTP + line; } } } else if (line.StartsWith("dmd.2.")) { string[] tokens = line.Split('.'); if (tokens.Length > 2 && !int.TryParse(tokens[2], out subVersion)) { subVersion = latestVer2; } if (tokens[tokens.Length - 1].Equals("zip", StringComparison.CurrentCultureIgnoreCase)) { if (latestVer2 < subVersion) { latestVer2 = subVersion; url2 = DIGITAL_MARS_HTTP + line; } } } } } response.Close(); } ver1.SubVersion = latestVer1; ver1.Url = url1; ver2.SubVersion = latestVer2; ver2.Url = url2; } catch (Exception ex) { ver1.Error = ERROR_PREFIX + ex.Message + Environment.NewLine + ex.StackTrace; ver2.Error = ERROR_PREFIX + ex.Message + Environment.NewLine + ex.StackTrace; } versions[1] = ver1; versions[2] = ver2; StringBuilder sb = new StringBuilder(); foreach (CompilerVersion ver in versions.Values) { sb.Append(ver.ToString()).Append("\r\n"); } File.WriteAllText(DataFile.FullName, sb.ToString()); } } }