private static Tuple <string, List <ModuleDefinition> > GenerateProject(string msBuildPath, string workingDir, AssemblyDefinition definition, bool lib) { if (workingDir == null) { throw new ArgumentNullException(nameof(workingDir)); } if (definition == null) { throw new ArgumentNullException(nameof(definition)); } if (!Directory.Exists(workingDir)) { throw new DirectoryNotFoundException("Can not find the working directory: " + workingDir); } Logger.Log(LogType.Log, "Generating csproject File...", 1); if (lib) { DotNetHelper.NewLib(msBuildPath, workingDir, definition.AssemblyName); } else { DotNetHelper.NewCommandLine(msBuildPath, workingDir, definition.AssemblyName); } File.Delete(Path.Combine(workingDir, definition.AssemblyName, lib ? "Class1.cs" : "Program.cs")); //Delete Default Class string projectFile = Path.Combine(workingDir, definition.AssemblyName, definition.AssemblyName + ".csproj"); List <ModuleDefinition> modules = new List <ModuleDefinition>(); for (int i = 0; i < definition.IncludedModules.Count; i++) { if (modules.Count(x => x.Name == definition.IncludedModules[i].Name) == 0) { DiscoverModules(definition.IncludedModules[i], modules); } } Logger.Log(LogType.Log, $"Discovered {modules.Count} Modules.", 1); CSharpProject p = ProjectLoader.LoadProject(projectFile); foreach (ModuleDefinition defintionDefinition in modules) { for (int i = 0; i < defintionDefinition.Packages.Length; i++) { p.AddReference(defintionDefinition.Packages[i]); } for (int i = 0; i < defintionDefinition.EmbeddedFiles.Length; i++) { p.AddReference(defintionDefinition.EmbeddedFiles[i]); } } File.Delete(projectFile); p.Save(projectFile); return(new Tuple <string, List <ModuleDefinition> >(projectFile, modules)); }
private static Tuple <string, List <ModuleDefinition> > GenerateProject(string msBuildPath, string workingDir, AssemblyDefinition definition, bool lib = true) { if (workingDir == null) { throw new ArgumentNullException(nameof(workingDir)); } if (definition == null) { throw new ArgumentNullException(nameof(definition)); } if (!Directory.Exists(workingDir)) { throw new DirectoryNotFoundException("Can not find the working directory: " + workingDir); } Logger.Log(LogType.Log, "Generating csproject File..."); DotNetHelper.New(msBuildPath, workingDir, definition.AssemblyName, lib); File.Delete(Path.Combine(workingDir, definition.AssemblyName, lib ? "Class1.cs" : "Program.cs")); //Delete Default Class string projectFile = Path.Combine(workingDir, definition.AssemblyName, definition.AssemblyName + ".csproj"); List <ModuleDefinition> modules = new List <ModuleDefinition>(); for (int i = 0; i < definition.IncludedModules.Count; i++) { if (modules.Count(x => x.Name == definition.IncludedModules[i].Name) == 0) { DiscoverModules(definition.IncludedModules[i], modules); } } Logger.Log(LogType.Log, $"Discovered {modules.Count} Modules."); CSharpProject p = ProjectLoader.LoadProject(projectFile); foreach (ModuleDefinition defintionDefinition in modules) { for (int i = 0; i < defintionDefinition.Packages.Length; i++) { p.AddReference(defintionDefinition.Packages[i]); } //for (int i = 0; i < defintionDefinition.Projects.Length; i++) //{ // CSharpReference r = PrepareForTransfer(defintionDefinition.Projects[i], // defintionDefinition); // string path = r.Attributes["Include"]; // if (modules.Count(x => path == Path.GetFullPath(Path.Combine(x.RootDirectory, x.Name + ".csproj"))) == 0) // { // p.AddReference(r); // } //} for (int i = 0; i < defintionDefinition.EmbeddedFiles.Length; i++) { p.AddReference(defintionDefinition.EmbeddedFiles[i]); } } File.Delete(projectFile); p.Save(projectFile); return(new Tuple <string, List <ModuleDefinition> >(projectFile, modules)); }