public bool BuildProject() { Log = ""; bool buildResultOK = false; BuildResultDll = BuildResultSymbols = ""; BuildResultAssets = null; try { using (bLogger BuildLogger = new bLogger()) { // usage Microsoft.Build.BuildEngine.Engine is prevelegy of MONO runtime Microsoft.Build.BuildEngine.Engine eng = Microsoft.Build.BuildEngine.Engine.GlobalEngine; eng.RegisterLogger(BuildLogger); Microsoft.Build.BuildEngine.Project prj = new Microsoft.Build.BuildEngine.Project(eng); prj.Load(ProjectLocation); logger.Debug("building project: {0}", ProjectLocation); // todo: add configuration set option if (!string.IsNullOrWhiteSpace(this.Configuration)) { eng.GlobalProperties.SetProperty("Configuration", this.Configuration); } string outd = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "_tempArtifacts"); eng.GlobalProperties.SetProperty("OutputPath", outd); eng.GlobalProperties.SetProperty("Platform", "AnyCPU"); string fileLib = System.IO.Path.Combine(outd, prj.GetEvaluatedProperty("TargetFileName")); string fileSymbols = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(fileLib), System.IO.Path.GetFileNameWithoutExtension(fileLib) + ".mdb"); buildResultOK = prj.Build(); eng.UnregisterAllLoggers(); Log = BuildLogger.Result(); if (buildResultOK) { BuildResultDll = fileLib; BuildResultSymbols = fileSymbols; List <string> files = new List <string>(); foreach (string F in System.IO.Directory.GetFiles(System.IO.Path.GetDirectoryName(fileLib))) {// TODO: not recursive! not now... if (F != BuildResultDll && F != BuildResultSymbols) { files.Add(F); } } BuildResultAssets = files.ToArray(); } } } catch (Exception e) { Log += string.Format("major exception while build: {0}", e.Message); } return(buildResultOK); }
private void AddImportTargets() { var msBuildEngine = new Microsoft.Build.BuildEngine.Engine(); foreach (Project prj in _solution.Projects) { prj.Save(); var fileName = prj.FullName; var prjName = prj.Name; SolutionFolder folder = null; if (prj.ParentProjectItem != null) { folder = (SolutionFolder)prj.ParentProjectItem.ContainingProject.Object; } _solution.Remove(prj); var msBuildProj = new Microsoft.Build.BuildEngine.Project(msBuildEngine); msBuildProj.Load(fileName); msBuildProj.Imports.AddNewImport(@"$(SolutionDir)\.nuget\nuget.targets", null); if (prjName.EndsWith(".Common")) { msBuildProj.Imports.AddNewImport(@"$(SolutionDir)\.zetbox\common.targets", null); } else if (prjName.EndsWith(".Client")) { msBuildProj.Imports.AddNewImport(@"$(SolutionDir)\.zetbox\client.targets", null); } else if (prjName.EndsWith(".Client.WPF")) { msBuildProj.Imports.AddNewImport(@"$(SolutionDir)\.zetbox\clientwpf.targets", null); } else if (prjName.EndsWith(".WPF")) { msBuildProj.Imports.AddNewImport(@"$(SolutionDir)\.zetbox\wpf.targets", null); } else if (prjName.EndsWith(".Server")) { msBuildProj.Imports.AddNewImport(@"$(SolutionDir)\.zetbox\server.targets", null); } msBuildProj.Save(fileName); if (folder != null) { folder.AddFromFile(fileName); } else { _solution.AddFromFile(fileName); } } }
public MSBuildProject(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir) : base(xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir) { string cfgname = solutionTask.Configuration; string platform = solutionTask.Platform; _msbuild = MSBuildEngine.CreateMSEngine(solutionTask); _msproj = new Microsoft.Build.BuildEngine.Project(_msbuild); _msproj.FullFileName = projectPath; _msproj.LoadXml(xmlDefinition.OuterXml); _msproj.GlobalProperties.SetProperty("Configuration", cfgname); SetPlatform (platform); if (outputDir != null) _msproj.GlobalProperties.SetProperty("OutputPath", outputDir.FullName); //evaluating _guid = _msproj.GetEvaluatedProperty("ProjectGuid"); _projectDirectory = new DirectoryInfo(_msproj.GetEvaluatedProperty("ProjectDir")); _projectPath = _msproj.GetEvaluatedProperty("ProjectPath"); ProjectEntry projectEntry = solution.ProjectEntries [_guid]; if (projectEntry != null && projectEntry.BuildConfigurations != null) { foreach (ConfigurationMapEntry ce in projectEntry.BuildConfigurations) { Configuration projectConfig = ce.Value; ProjectConfigurations[projectConfig] = new MSBuildConfiguration(this, _msproj, projectConfig); } } else { Configuration projectConfig = new Configuration (cfgname, platform); ProjectConfigurations[projectConfig] = new MSBuildConfiguration(this, _msproj, projectConfig); } //references _references = new ArrayList(); Microsoft.Build.BuildEngine.BuildItemGroup refs = _msproj.GetEvaluatedItemsByName("Reference"); foreach (Microsoft.Build.BuildEngine.BuildItem r in refs) { string rpath = r.FinalItemSpec; string priv = r.GetMetadata("Private"); string hintpath = r.GetMetadata("HintPath"); ReferenceBase reference = new MSBuildAssemblyReference( xmlDefinition, ReferencesResolver, this, gacCache, rpath, priv, hintpath); _references.Add(reference); } refs = _msproj.GetEvaluatedItemsByName("ProjectReference"); foreach (Microsoft.Build.BuildEngine.BuildItem r in refs) { string pguid = r.GetMetadata("Project"); string pname = r.GetMetadata("Name"); string rpath = r.FinalItemSpec; string priv = r.GetMetadata("Private"); ReferenceBase reference = new MSBuildProjectReference( ReferencesResolver, this, solution, tfc, gacCache, outputDir, pguid, pname, rpath, priv); _references.Add(reference); } }
public static Microsoft.Build.BuildEngine.Engine CreateMSEngine(NAnt.VSNet.Tasks.SolutionTask solutionTask) { if (_msbuild != null) { return(_msbuild); } // map current target framework to TargetDotNetFrameworkVersion TargetDotNetFrameworkVersion frameworkVersion = GetTargetDotNetFrameworkVersion( solutionTask.Project.TargetFramework); // use the framework directory as BinPath string frameworkDir = ToolLocationHelper.GetPathToDotNetFramework( frameworkVersion); _msbuild = new Microsoft.Build.BuildEngine.Engine(frameworkDir); _msbuild.UnregisterAllLoggers(); _msbuild.RegisterLogger( new NAntLogger(solutionTask, solutionTask.Verbose ? Microsoft.Build.Framework.LoggerVerbosity.Normal : Microsoft.Build.Framework.LoggerVerbosity.Minimal ) ); /* * foreach (PropertyTask property in solutionTask.CustomProperties) { * string val; * // expand properties in context of current project for non-dynamic properties * if (!property.Dynamic) { * val = solutionTask.Project.ExpandProperties(property.Value, solutionTask.Location); * } * else * val = property.Value; * _msbuild.GlobalProperties.SetProperty(property.PropertyName, val); * } */ return(_msbuild); }
public static Microsoft.Build.BuildEngine.Engine CreateMSEngine(NAnt.VSNet.Tasks.SolutionTask solutionTask) { if (_msbuild!=null) { return _msbuild; } // map current target framework to TargetDotNetFrameworkVersion TargetDotNetFrameworkVersion frameworkVersion = GetTargetDotNetFrameworkVersion( solutionTask.Project.TargetFramework); // use the framework directory as BinPath string frameworkDir = ToolLocationHelper.GetPathToDotNetFramework( frameworkVersion); _msbuild = new Microsoft.Build.BuildEngine.Engine(frameworkDir); _msbuild.UnregisterAllLoggers(); _msbuild.RegisterLogger( new NAntLogger(solutionTask, solutionTask.Verbose ? Microsoft.Build.Framework.LoggerVerbosity.Normal : Microsoft.Build.Framework.LoggerVerbosity.Minimal ) ); /* foreach (PropertyTask property in solutionTask.CustomProperties) { string val; // expand properties in context of current project for non-dynamic properties if (!property.Dynamic) { val = solutionTask.Project.ExpandProperties(property.Value, solutionTask.Location); } else val = property.Value; _msbuild.GlobalProperties.SetProperty(property.PropertyName, val); } */ return _msbuild; }
private static bool BuildProjectWithOldOM(string projectFile, string[] targets, string toolsVersion, Microsoft.Build.BuildEngine.BuildPropertyGroup propertyBag, ILogger[] loggers, LoggerVerbosity verbosity, DistributedLoggerRecord[] distributedLoggerRecords, bool needToValidateProject, string schemaFile, int cpuCount) { string msbuildLocation = Path.GetDirectoryName(Assembly.GetAssembly(typeof(MSBuildApp)).Location); string localNodeProviderParameters = "msbuildlocation=" + msbuildLocation; /*This assembly is the exe*/ ; localNodeProviderParameters += ";nodereuse=false"; Microsoft.Build.BuildEngine.Engine engine = new Microsoft.Build.BuildEngine.Engine(propertyBag, Microsoft.Build.BuildEngine.ToolsetDefinitionLocations.ConfigurationFile | Microsoft.Build.BuildEngine.ToolsetDefinitionLocations.Registry, cpuCount, localNodeProviderParameters); bool success = false; try { foreach (ILogger logger in loggers) { engine.RegisterLogger(logger); } // Targeted perf optimization for the case where we only have our own parallel console logger, and verbosity is quiet. In such a case // we know we won't emit any messages except for errors and warnings, so the engine should not bother even logging them. // If we're using the original serial console logger we can't do this, as it shows project started/finished context // around errors and warnings. // Telling the engine to not bother logging non-critical messages means that typically it can avoid loading any resources in the successful // build case. if (loggers.Length == 1 && verbosity == LoggerVerbosity.Quiet && loggers[0].Parameters.IndexOf("ENABLEMPLOGGING", StringComparison.OrdinalIgnoreCase) != -1 && loggers[0].Parameters.IndexOf("DISABLEMPLOGGING", StringComparison.OrdinalIgnoreCase) == -1 && loggers[0].Parameters.IndexOf("V=", StringComparison.OrdinalIgnoreCase) == -1 && // Console logger could have had a verbosity loggers[0].Parameters.IndexOf("VERBOSITY=", StringComparison.OrdinalIgnoreCase) == -1) // override with the /clp switch { // Must be exactly the console logger, not a derived type like the file logger. Type t1 = loggers[0].GetType(); Type t2 = typeof(ConsoleLogger); if (t1 == t2) { engine.OnlyLogCriticalEvents = true; } } Microsoft.Build.BuildEngine.Project project = null; try { project = new Microsoft.Build.BuildEngine.Project(engine, toolsVersion); } catch (InvalidOperationException e) { InitializationException.Throw("InvalidToolsVersionError", toolsVersion, e, false /*no stack*/); } project.IsValidated = needToValidateProject; project.SchemaFile = schemaFile; project.Load(projectFile); success = engine.BuildProject(project, targets); } // handle project file errors catch (InvalidProjectFileException) { // just eat the exception because it has already been logged } finally { // Unregister loggers and finish with engine engine.Shutdown(); } return success; }
public MSBuildProject(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir) : base(xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir) { string cfgname = solutionTask.Configuration; string platform = solutionTask.Platform; _msbuild = MSBuildEngine.CreateMSEngine(solutionTask); _msproj = new Microsoft.Build.BuildEngine.Project(_msbuild); _msproj.FullFileName = projectPath; _msproj.LoadXml(xmlDefinition.OuterXml); _msproj.GlobalProperties.SetProperty("Configuration", cfgname); SetPlatform(platform); if (outputDir != null) { _msproj.GlobalProperties.SetProperty("OutputPath", outputDir.FullName); } //evaluating _guid = _msproj.GetEvaluatedProperty("ProjectGuid"); _projectDirectory = new DirectoryInfo(_msproj.GetEvaluatedProperty("ProjectDir")); _projectPath = _msproj.GetEvaluatedProperty("ProjectPath"); ProjectEntry projectEntry = solution.ProjectEntries [_guid]; if (projectEntry != null && projectEntry.BuildConfigurations != null) { foreach (ConfigurationMapEntry ce in projectEntry.BuildConfigurations) { Configuration projectConfig = ce.Value; ProjectConfigurations[projectConfig] = new MSBuildConfiguration(this, _msproj, projectConfig); } } else { Configuration projectConfig = new Configuration(cfgname, platform); ProjectConfigurations[projectConfig] = new MSBuildConfiguration(this, _msproj, projectConfig); } //references _references = new ArrayList(); Microsoft.Build.BuildEngine.BuildItemGroup refs = _msproj.GetEvaluatedItemsByName("Reference"); foreach (Microsoft.Build.BuildEngine.BuildItem r in refs) { string rpath = r.FinalItemSpec; string priv = r.GetMetadata("Private"); string hintpath = r.GetMetadata("HintPath"); ReferenceBase reference = new MSBuildAssemblyReference( xmlDefinition, ReferencesResolver, this, gacCache, rpath, priv, hintpath); _references.Add(reference); } refs = _msproj.GetEvaluatedItemsByName("ProjectReference"); foreach (Microsoft.Build.BuildEngine.BuildItem r in refs) { string pguid = r.GetMetadata("Project"); string pname = r.GetMetadata("Name"); string rpath = r.FinalItemSpec; string priv = r.GetMetadata("Private"); ReferenceBase reference = new MSBuildProjectReference( ReferencesResolver, this, solution, tfc, gacCache, outputDir, pguid, pname, rpath, priv); _references.Add(reference); } }
public Microsoft.Build.BuildEngine.Project ConvertInMemory(Microsoft.Build.BuildEngine.Engine engine, Microsoft.Build.BuildEngine.ProjectLoadSettings projectLoadSettings) { throw null; }
public Microsoft.Build.BuildEngine.Project ConvertInMemory(Microsoft.Build.BuildEngine.Engine engine) { throw null; }
private void StyleCopCoreAddSettingsPages(object sender, AddSettingsPagesEventArgs e) { Param.Ignore(sender); Param.AssertNotNull(e, "e"); Project project = ProjectUtilities.GetActiveProject(); string fullName = ProjectUtilities.GetProjectFullName(project); if (string.IsNullOrEmpty(fullName)) { return; } project.Save(); Microsoft.Build.BuildEngine.Engine engine = new Microsoft.Build.BuildEngine.Engine(); Microsoft.Build.BuildEngine.Project proj = engine.CreateNewProject(); proj.Load(project.FullName); e.Add(new BuildIntegrationOptions(proj)); }
private void AddImportTargets() { _messages.WriteLine("Adding import targets"); var msBuildEngine = new Microsoft.Build.BuildEngine.Engine(); foreach (Project prj in _solution.Projects) { prj.Save(); var fileName = prj.FullName; var prjName = prj.Name; SolutionFolder folder = null; if (prj.ParentProjectItem != null) { folder = (SolutionFolder)prj.ParentProjectItem.ContainingProject.Object; } _solution.Remove(prj); var msBuildProj = new Microsoft.Build.BuildEngine.Project(msBuildEngine); msBuildProj.Load(fileName); msBuildProj.Imports.AddNewImport(@"$(SolutionDir)\.nuget\nuget.targets", null); if (prjName == ToProjectName("Common")) { msBuildProj.Imports.AddNewImport(@"$(SolutionDir)\.zetbox\common.targets", null); } else if (prjName == ToProjectName("Client") || prjName == ToProjectName("Client.Tests")) { msBuildProj.Imports.AddNewImport(@"$(SolutionDir)\.zetbox\client.targets", null); } else if (prjName == ToProjectName("Client.WPF")) { msBuildProj.Imports.AddNewImport(@"$(SolutionDir)\.zetbox\clientwpf.targets", null); } else if (prjName == ToProjectName("WPF")) { msBuildProj.Imports.AddNewImport(@"$(SolutionDir)\.zetbox\wpf.targets", null); } else if (prjName == ToProjectName("Server") || prjName == ToProjectName("Server.Tests") || prjName == ToProjectName("Migrate")) { msBuildProj.Imports.AddNewImport(@"$(SolutionDir)\.zetbox\server.targets", null); } else if (prjName == ToProjectName("Server.Migrations")) { msBuildProj.Imports.AddNewImport(@"$(SolutionDir)\.zetbox\fallback.targets", null); } msBuildProj.Save(fileName); if (folder != null) { folder.AddFromFile(fileName); } else { _solution.AddFromFile(fileName); } } }
public OldProject ConvertInMemory ( OldEngine engine, ProjectLoadSettings projectLoadSettings ) { this.ConvertInMemoryToMSBuildProject(); OldProject oldProject = new OldProject(engine); using (StringReader reader = new StringReader(xmakeProject.RawXml)) { oldProject.Load(reader); } return oldProject; }
public OldProject ConvertInMemory ( OldEngine engine ) { return ConvertInMemory(engine, ProjectLoadSettings.None); }
public Project(Microsoft.Build.BuildEngine.Engine engine) { }
public Project(Microsoft.Build.BuildEngine.Engine engine, string toolsVersion) { }
public PackageTestEnvironment() { // Create the project project = new ProjectTestClass(); // Site the project services = Microsoft.VsSDK.UnitTestLibrary.OleServiceProvider.CreateOleServiceProviderWithBasicServices(); LocalRegistryMock localRegistry = new LocalRegistryMock(); localRegistry.RegistryRoot = @"Software\Microsoft\VisualStudio\9.0"; services.AddService(typeof(SLocalRegistry), localRegistry, true); BaseMock mockConfigMgr = ConfigurationManagerFactory.GetInstance(); BaseMock extensibility = ExtensibilityFactory.GetInstance(); extensibility.AddMethodReturnValues( string.Format("{0}.{1}", typeof(IVsExtensibility3).FullName, "GetConfigMgr"), new object[] { 0, null, null, mockConfigMgr }); services.AddService(typeof(IVsExtensibility), extensibility, false); project.SetSite(services); // Init the msbuild engine if (null == initEngine) { initEngine = typeof(VisualStudio.Project.Utilities).GetMethod("InitializeMsBuildEngine", BindingFlags.NonPublic | BindingFlags.Static); } Microsoft.Build.BuildEngine.Engine engine = initEngine.Invoke(null, new object[2] { null, services }) as Microsoft.Build.BuildEngine.Engine; Assert.IsNotNull(engine, "MSBuild Engine could not be initialized"); // Retrieve the project file content, load it and save it string fullpath = Path.Combine(new DirectoryInfo(Assembly.GetExecutingAssembly().Location).Parent.FullName, "TestProject.proj"); if (string.IsNullOrEmpty(projectXml)) { projectXml = Properties.Resources.TestProject; using (TextWriter writer = new StreamWriter(fullpath)) { writer.Write(projectXml); } } // Init the msbuild project if (null == initProject) { initProject = typeof(VisualStudio.Project.Utilities).GetMethod("InitializeMsBuildProject", BindingFlags.NonPublic | BindingFlags.Static); } Microsoft.Build.BuildEngine.Project buildProject = initProject.Invoke(null, new object[2] { engine, fullpath }) as Microsoft.Build.BuildEngine.Project; Assert.IsNotNull(buildProject, "MSBuild project not initialized correctly in InitializeMsBuildProject"); //Verify that we can set the build project on the projectnode PropertyInfo buildProjectInfo = typeof(VisualStudio.Project.ProjectNode).GetProperty("BuildProject", BindingFlags.Instance | BindingFlags.NonPublic); buildProjectInfo.SetValue(project, buildProject, new object[0]); // Now the project is opened, so we can update its internal variable. if (null == projectOpened) { projectOpened = typeof(VisualStudio.Project.ProjectNode).GetField("projectOpened", BindingFlags.Instance | BindingFlags.NonPublic); } projectOpened.SetValue(project, true); }