public override bool Execute() { if (targets == null || targets.Length == 0) { return(true); } Hashtable targets_table = new Hashtable(); if (!RunEachTargetSeparately) { bool ret = BuildEngine.BuildProjectFile(null, targets, null, targets_table); foreach (ITaskItem[] items in targets_table.Values) { if (items != null) { targetOutputs_list.AddRange(items); } } return(ret); } // RunEachTargetSeparately bool allPassed = true; for (int i = 0; i < targets.Length; i++) { string target = targets [i]; bool result = BuildEngine.BuildProjectFile(BuildEngine.ProjectFileOfTaskNode, new string[] { target }, null, targets_table); if (allPassed && !result) { allPassed = false; } if (!targets_table.Contains(target)) { continue; } ITaskItem [] items = (ITaskItem[])targets_table [target]; if (items != null) { targetOutputs_list.AddRange(items); } } return(allPassed); }
ProjectInfoResponse HandleProjectInfoRequest(ProjectInfoRequest req) { var targetsPath = typeof(AvaloniaIdeTask).GetTypeInfo().Assembly.GetModules()[0].FullyQualifiedName; targetsPath = Path.Combine(Path.GetDirectoryName(targetsPath), "avalonia-ide.targets"); var props = new Dictionary <string, string> { ["DesignTimeBuild"] = "true", ["BuildProjectReferences"] = "false", ["_ResolveReferenceDependencies"] = "true", ["SolutionDir"] = req.SolutionDirectory, ["ProvideCommandLineInvocation"] = "true", ["ProvideCommandLineArgs"] = "true", ["SkipCompilerExecution"] = "true", ["TargetFramework"] = req.TargetFramework, ["CustomBeforeMicrosoftCommonTargets"] = targetsPath, ["AvaloniaRandom"] = Guid.NewGuid().ToString(), ["AvaloniaForceCoreCompile"] = "true" }; var outputs = new Dictionary <string, ITaskItem[]>(); if (!BuildEngine.BuildProjectFile(req.FullPath, new[] { "ResolveAssemblyReferences", "GetTargetPath", "AvaloniaGetCscCommandLine", "AvaloniaGetEmbeddedResources", "AvaloniaGetAvaloniaResources" }, props, outputs)) { throw new Exception("Build failed"); } var result = new ProjectInfoResponse { TargetPath = outputs["GetTargetPath"][0].ItemSpec, EmbeddedResources = outputs["AvaloniaGetEmbeddedResources"].Select(x => x.ItemSpec).ToList(), AvaloniaResources = outputs["AvaloniaGetAvaloniaResources"].Select(x => x.ItemSpec).ToList(), }; if (outputs.ContainsKey("ResolveAssemblyReferences")) { result.MetaDataReferences = outputs["ResolveAssemblyReferences"].Select(x => x.ItemSpec).ToList(); } if (outputs.ContainsKey("AvaloniaGetCscCommandLine")) { result.CscCommandLine = outputs["AvaloniaGetCscCommandLine"].Select(x => x.ItemSpec).ToList(); } return(result); }
private string GetLatestReleasePath() { var projectFile = new FileInfo(Path.Combine(ReleasedOutputPath, "latest", "project.csproj")); if (!projectFile.Directory.Exists) { projectFile.Directory.Create(); } using (var stream = projectFile.CreateText()) stream.WriteLine($"<Project Sdk=\"Microsoft.NET.Sdk\"><PropertyGroup><TargetFramework>{TargetFramework}</TargetFramework></PropertyGroup><ItemGroup><PackageReference Include=\"{PackageId}\" Version=\"*\" /></ItemGroup></Project>"); Log.LogMessage(MessageImportance.High, $"Attempting to acquire latest released version of {PackageId} for {TargetFramework}."); if (BuildEngine.BuildProjectFile(projectFile.FullName, new[] { "Restore", "Build" }, new Dictionary <string, string> { { "Configuration", "Release" } }, null)) { return(Path.Combine(projectFile.DirectoryName, "bin", "Release", TargetFramework, Path.GetFileName(TargetPath))); } return(string.Empty); }
BuildProjectResponse HandleBuildProjectRequest(BuildProjectRequest req) { var targetsPath = typeof(AvaloniaIdeTask).GetTypeInfo().Assembly.GetModules()[0].FullyQualifiedName; targetsPath = Path.Combine(Path.GetDirectoryName(targetsPath), "avalonia-ide.targets"); var props = new Dictionary <string, string> { ["DesignTimeBuild"] = "false", ["BuildProjectReferences"] = "false", ["_ResolveReferenceDependencies"] = "true", ["SolutionDir"] = req.SolutionDirectory, ["ProvideCommandLineInvocation"] = "false", ["SkipCompilerExecution"] = "false", ["BuildProjectReferences"] = "false", ["TargetFramework"] = req.TargetFramework, ["CustomBeforeMicrosoftCommonTargets"] = targetsPath }; var outputs = new Dictionary <string, ITaskItem[]>(); var status = BuildEngine.BuildProjectFile(req.FullPath, null, props, outputs); var result = new BuildProjectResponse { Success = status }; if (!status) { } if (outputs.ContainsKey("Build")) { result.OutputAssemblies = outputs["Build"].Select(item => item.ItemSpec).ToList(); } return(result); }
public override bool Execute() { bool retValue = true; // Verification try { retValue = BuildEngine.BuildProjectFile(TemporaryTargetAssemblyProjectName, new string[] { CompileTargetName }, null, null); // Delete the temporary project file and generated files unless diagnostic mode has been requested if (!GenerateTemporaryTargetAssemblyDebuggingInformation) { try { File.Delete(TemporaryTargetAssemblyProjectName); DirectoryInfo intermediateOutputPath = new DirectoryInfo(IntermediateOutputPath); foreach (FileInfo temporaryProjectFile in intermediateOutputPath.EnumerateFiles(string.Concat(Path.GetFileNameWithoutExtension(TemporaryTargetAssemblyProjectName), "*"))) { temporaryProjectFile.Delete(); } } catch (IOException e) { // Failure to delete the file is a non fatal error Log.LogWarningFromException(e); } } } catch (Exception e) { Log.LogErrorFromException(e); retValue = false; } return(retValue); }
public override bool Execute() { bool retValue = true; // Verification try { XmlDocument xmlProjectDoc = null; xmlProjectDoc = new XmlDocument( ); xmlProjectDoc.Load(CurrentProject); // // remove all the WinFX specific item lists // ApplicationDefinition, Page, MarkupResource and Resource // RemoveItemsByName(xmlProjectDoc, APPDEFNAME); RemoveItemsByName(xmlProjectDoc, PAGENAME); RemoveItemsByName(xmlProjectDoc, MARKUPRESOURCENAME); RemoveItemsByName(xmlProjectDoc, RESOURCENAME); // Replace the Reference Item list with ReferencePath RemoveItemsByName(xmlProjectDoc, REFERENCETYPENAME); AddNewItems(xmlProjectDoc, ReferencePathTypeName, ReferencePath); // Add GeneratedCodeFiles to Compile item list. AddNewItems(xmlProjectDoc, CompileTypeName, GeneratedCodeFiles); string currentProjectName = Path.GetFileNameWithoutExtension(CurrentProject); string currentProjectExtension = Path.GetExtension(CurrentProject); // Create a random file name // This can fix the problem of project cache in VS.NET environment. // // GetRandomFileName( ) could return any possible file name and extension // Since this temporary file will be used to represent an MSBUILD project file, // we will use the same extension as that of the current project file // string randomFileName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()); // Don't call Path.ChangeExtension to append currentProjectExtension. It will do // odd things with project names that already contains a period (like System.Windows. // Contols.Ribbon.csproj). Instead, just append the extension - after all, we already know // for a fact that this name (i.e., tempProj) lacks a file extension. string tempProj = string.Join("_", currentProjectName, randomFileName, WPFTMP); tempProj = tempProj + currentProjectExtension; // Save the xmlDocument content into the temporary project file. xmlProjectDoc.Save(tempProj); // // Invoke MSBUILD engine to build this temporary project file. // Hashtable globalProperties = new Hashtable(3); // Add AssemblyName, IntermediateOutputPath and _TargetAssemblyProjectName to the global property list // Note that _TargetAssemblyProjectName is not defined as a property with Output attribute - that doesn't do us much // good here. We need _TargetAssemblyProjectName to be a well-known property in the new (temporary) project // file, and having it be available in the current MSBUILD process is not useful. globalProperties[intermediateOutputPathPropertyName] = IntermediateOutputPath; globalProperties[assemblyNamePropertyName] = AssemblyName; globalProperties[targetAssemblyProjectNamePropertyName] = currentProjectName; retValue = BuildEngine.BuildProjectFile(tempProj, new string[] { CompileTargetName }, globalProperties, null); // Delete the temporary project file unless diagnostic mode has been requested if (!GenerateTemporaryTargetAssemblyDebuggingInformation) { try { File.Delete(tempProj); } catch (IOException e) { // Failure to delete the file is a non fatal error Log.LogWarningFromException(e); } } } catch (Exception e) { Log.LogErrorFromException(e); retValue = false; } return(retValue); }
private bool ExecuteGenerateTemporaryTargetAssemblyWithPackageReferenceSupport() { bool retValue = true; // // Create the temporary target assembly project // try { XmlDocument xmlProjectDoc = null; xmlProjectDoc = new XmlDocument( ); xmlProjectDoc.Load(CurrentProject); // remove all the WinFX specific item lists // ApplicationDefinition, Page, MarkupResource and Resource RemoveItemsByName(xmlProjectDoc, APPDEFNAME); RemoveItemsByName(xmlProjectDoc, PAGENAME); RemoveItemsByName(xmlProjectDoc, MARKUPRESOURCENAME); RemoveItemsByName(xmlProjectDoc, RESOURCENAME); // Replace the Reference Item list with ReferencePath RemoveItemsByName(xmlProjectDoc, REFERENCETYPENAME); AddNewItems(xmlProjectDoc, ReferencePathTypeName, ReferencePath); // Add GeneratedCodeFiles to Compile item list. AddNewItems(xmlProjectDoc, CompileTypeName, GeneratedCodeFiles); // Replace implicit SDK imports with explicit SDK imports ReplaceImplicitImports(xmlProjectDoc); // Add properties required for temporary assembly compilation var properties = new List <(string PropertyName, string PropertyValue)> { (nameof(AssemblyName), AssemblyName), (nameof(IntermediateOutputPath), IntermediateOutputPath), (nameof(BaseIntermediateOutputPath), BaseIntermediateOutputPath), ("_TargetAssemblyProjectName", Path.GetFileNameWithoutExtension(CurrentProject)), (nameof(Analyzers), Analyzers) }; AddNewProperties(xmlProjectDoc, properties); // Save the xmlDocument content into the temporary project file. xmlProjectDoc.Save(TemporaryTargetAssemblyProjectName); // Disable conflicting Arcade SDK workaround that imports NuGet props/targets Hashtable globalProperties = new Hashtable(1); globalProperties["_WpfTempProjectNuGetFilePathNoExt"] = ""; // // Compile the temporary target assembly project // retValue = BuildEngine.BuildProjectFile(TemporaryTargetAssemblyProjectName, new string[] { CompileTargetName }, globalProperties, null); // Delete the temporary project file and generated files unless diagnostic mode has been requested if (!GenerateTemporaryTargetAssemblyDebuggingInformation) { try { File.Delete(TemporaryTargetAssemblyProjectName); DirectoryInfo intermediateOutputPath = new DirectoryInfo(IntermediateOutputPath); foreach (FileInfo temporaryProjectFile in intermediateOutputPath.EnumerateFiles(string.Concat(Path.GetFileNameWithoutExtension(TemporaryTargetAssemblyProjectName), "*"))) { temporaryProjectFile.Delete(); } } catch (IOException e) { // Failure to delete the file is a non fatal error Log.LogWarningFromException(e); } } } catch (Exception e) { Log.LogErrorFromException(e); retValue = false; } return(retValue); }
private bool ExecuteGenerateTemporaryTargetAssemblyWithPackageReferenceSupport() { bool retValue = true; // // Create the temporary target assembly project // try { XmlDocument xmlProjectDoc = null; xmlProjectDoc = new XmlDocument( ); xmlProjectDoc.Load(CurrentProject); // remove all the WinFX specific item lists // ApplicationDefinition, Page, MarkupResource and Resource RemoveItemsByName(xmlProjectDoc, APPDEFNAME); RemoveItemsByName(xmlProjectDoc, PAGENAME); RemoveItemsByName(xmlProjectDoc, MARKUPRESOURCENAME); RemoveItemsByName(xmlProjectDoc, RESOURCENAME); // Replace the Reference Item list with ReferencePath RemoveItemsByName(xmlProjectDoc, REFERENCETYPENAME); AddNewItems(xmlProjectDoc, ReferencePathTypeName, ReferencePath); // Add GeneratedCodeFiles to Compile item list. AddNewItems(xmlProjectDoc, CompileTypeName, GeneratedCodeFiles); // Replace implicit SDK imports with explicit SDK imports ReplaceImplicitImports(xmlProjectDoc); // Add properties required for temporary assembly compilation var properties = new List <(string PropertyName, string PropertyValue)> { (nameof(AssemblyName), AssemblyName), (nameof(IntermediateOutputPath), IntermediateOutputPath), (nameof(BaseIntermediateOutputPath), BaseIntermediateOutputPath), (nameof(MSBuildProjectExtensionsPath), MSBuildProjectExtensionsPath), ("_TargetAssemblyProjectName", Path.GetFileNameWithoutExtension(CurrentProject)), (nameof(Analyzers), Analyzers) }; AddNewProperties(xmlProjectDoc, properties); // Save the xmlDocument content into the temporary project file. xmlProjectDoc.Save(TemporaryTargetAssemblyProjectName); // // Compile the temporary target assembly project // Dictionary <string, ITaskItem[]> targetOutputs = new Dictionary <string, ITaskItem[]>(); retValue = BuildEngine.BuildProjectFile(TemporaryTargetAssemblyProjectName, new string[] { CompileTargetName }, null, targetOutputs); // If the inner build succeeds, retrieve the path to the local type assembly from the task's TargetOutputs. if (retValue) { // See Microsoft.WinFX.targets: TargetOutputs from '_CompileTemporaryAssembly' will always contain one item. // <Target Name="_CompileTemporaryAssembly" DependsOnTargets="$(_CompileTemporaryAssemblyDependsOn)" Returns="$(IntermediateOutputPath)$(TargetFileName)"/> Debug.Assert(targetOutputs.ContainsKey(CompileTargetName)); Debug.Assert(targetOutputs[CompileTargetName].Length == 1); TemporaryAssemblyForLocalTypeReference = targetOutputs[CompileTargetName][0].ItemSpec; } // Delete the temporary project file and generated files unless diagnostic mode has been requested if (!GenerateTemporaryTargetAssemblyDebuggingInformation) { try { File.Delete(TemporaryTargetAssemblyProjectName); DirectoryInfo intermediateOutputPath = new DirectoryInfo(IntermediateOutputPath); foreach (FileInfo temporaryProjectFile in intermediateOutputPath.EnumerateFiles(string.Concat(Path.GetFileNameWithoutExtension(TemporaryTargetAssemblyProjectName), "*"))) { temporaryProjectFile.Delete(); } } catch (IOException e) { // Failure to delete the file is a non fatal error Log.LogWarningFromException(e); } } } catch (Exception e) { Log.LogErrorFromException(e); retValue = false; } return(retValue); }
private bool ExecuteLegacyGenerateTemporaryTargetAssembly() { bool retValue = true; // Verification try { XmlDocument xmlProjectDoc = null; xmlProjectDoc = new XmlDocument( ); xmlProjectDoc.Load(CurrentProject); // // remove all the WinFX specific item lists // ApplicationDefinition, Page, MarkupResource and Resource // RemoveItemsByName(xmlProjectDoc, APPDEFNAME); RemoveItemsByName(xmlProjectDoc, PAGENAME); RemoveItemsByName(xmlProjectDoc, MARKUPRESOURCENAME); RemoveItemsByName(xmlProjectDoc, RESOURCENAME); // Replace the Reference Item list with ReferencePath RemoveItemsByName(xmlProjectDoc, REFERENCETYPENAME); AddNewItems(xmlProjectDoc, ReferencePathTypeName, ReferencePath); // Add GeneratedCodeFiles to Compile item list. AddNewItems(xmlProjectDoc, CompileTypeName, GeneratedCodeFiles); string currentProjectName = Path.GetFileNameWithoutExtension(CurrentProject); string currentProjectExtension = Path.GetExtension(CurrentProject); // Create a random file name // This can fix the problem of project cache in VS.NET environment. // // GetRandomFileName( ) could return any possible file name and extension // Since this temporary file will be used to represent an MSBUILD project file, // we will use the same extension as that of the current project file // string randomFileName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()); // Don't call Path.ChangeExtension to append currentProjectExtension. It will do // odd things with project names that already contains a period (like System.Windows. // Contols.Ribbon.csproj). Instead, just append the extension - after all, we already know // for a fact that this name (i.e., tempProj) lacks a file extension. string tempProjPrefix = string.Join("_", currentProjectName, randomFileName, WPFTMP); string tempProj = tempProjPrefix + currentProjectExtension; // Save the xmlDocument content into the temporary project file. xmlProjectDoc.Save(tempProj); // // Invoke MSBUILD engine to build this temporary project file. // Hashtable globalProperties = new Hashtable(3); // Add AssemblyName, IntermediateOutputPath and _TargetAssemblyProjectName to the global property list // Note that _TargetAssemblyProjectName is not defined as a property with Output attribute - that doesn't do us much // good here. We need _TargetAssemblyProjectName to be a well-known property in the new (temporary) project // file, and having it be available in the current MSBUILD process is not useful. globalProperties[intermediateOutputPathPropertyName] = IntermediateOutputPath; globalProperties[assemblyNamePropertyName] = AssemblyName; globalProperties[targetAssemblyProjectNamePropertyName] = currentProjectName; Dictionary <string, ITaskItem[]> targetOutputs = new Dictionary <string, ITaskItem[]>(); retValue = BuildEngine.BuildProjectFile(tempProj, new string[] { CompileTargetName }, globalProperties, targetOutputs); // If the inner build succeeds, retrieve the path to the local type assembly from the task's TargetOutputs. if (retValue) { // See Microsoft.WinFX.targets: TargetOutputs from '_CompileTemporaryAssembly' will always contain one item. // <Target Name="_CompileTemporaryAssembly" DependsOnTargets="$(_CompileTemporaryAssemblyDependsOn)" Returns="$(IntermediateOutputPath)$(TargetFileName)"/> Debug.Assert(targetOutputs.ContainsKey(CompileTargetName)); Debug.Assert(targetOutputs[CompileTargetName].Length == 1); TemporaryAssemblyForLocalTypeReference = targetOutputs[CompileTargetName][0].ItemSpec; } // Delete the temporary project file and generated files unless diagnostic mode has been requested if (!GenerateTemporaryTargetAssemblyDebuggingInformation) { try { File.Delete(tempProj); DirectoryInfo intermediateOutputPath = new DirectoryInfo(IntermediateOutputPath); foreach (FileInfo temporaryProjectFile in intermediateOutputPath.EnumerateFiles(string.Concat(tempProjPrefix, "*"))) { temporaryProjectFile.Delete(); } } catch (IOException e) { // Failure to delete the file is a non fatal error Log.LogWarningFromException(e); } } } catch (Exception e) { Log.LogErrorFromException(e); retValue = false; } return(retValue); }
public override bool Execute() { // BuildEngine.BuildProjectFile is how the GenerateTemporaryTargetAssembly task builds projects. return(BuildEngine.BuildProjectFile(CurrentProject, new string[] { "ErrorTask" }, new Hashtable(), null)); }
public override bool Execute() { if (projects.Length == 0) { return(true); } string filename; bool result = true; stopOnFirstFailure = false; List <ITaskItem> outputItems = new List <ITaskItem> (); string currentDirectory = Environment.CurrentDirectory; Hashtable outputs; Dictionary <string, string> global_properties = SplitPropertiesToDictionary(); Dictionary <string, ITaskItem> projectsByFileName = new Dictionary <string, ITaskItem> (); foreach (ITaskItem project in projects) { filename = project.GetMetadata("FullPath"); if (!File.Exists(filename)) { Log.LogError("Could not find the project file '{0}'", filename); if (stopOnFirstFailure) { break; } continue; } Directory.SetCurrentDirectory(Path.GetDirectoryName(filename)); outputs = new Hashtable(); try { result = BuildEngine.BuildProjectFile(filename, targets, global_properties, outputs); } catch (InvalidProjectFileException e) { Log.LogError("Error building project {0}: {1}", filename, e.Message); result = false; } if (result) { // Metadata from the first item for the project file is copied ITaskItem first_item; if (!projectsByFileName.TryGetValue(filename, out first_item)) { projectsByFileName [filename] = first_item = project; } foreach (DictionaryEntry de in outputs) { ITaskItem [] array = (ITaskItem [])de.Value; foreach (ITaskItem item in array) { // DONT share items! ITaskItem new_item = new TaskItem(item); // copy the metadata from original @project to here // CopyMetadataTo does _not_ overwrite first_item.CopyMetadataTo(new_item); outputItems.Add(new_item); //FIXME: Correctly rebase output paths to be relative to the // calling project //if (rebaseOutputs) // File.Copy (item.ItemSpec, Path.Combine (currentDirectory, item.ItemSpec), true); } } } else { if (stopOnFirstFailure) { break; } } Directory.SetCurrentDirectory(currentDirectory); } if (result) { targetOutputs = outputItems.ToArray(); } Directory.SetCurrentDirectory(currentDirectory); return(result); }
//------------------------------------------------------ // // Public Methods // //------------------------------------------------------ #region Public Methods /// <summary> /// ITask Execute method /// </summary> /// <returns></returns> public override bool Execute() { bool retValue = true; // Verification try { XmlDocument xmlProjectDoc = null; xmlProjectDoc = new XmlDocument( ); xmlProjectDoc.Load(CurrentProject); // // remove all the WinFX specific item lists // ApplicationDefinition, Page, MarkupResource and Resource // RemoveItemsByName(xmlProjectDoc, APPDEFNAME); RemoveItemsByName(xmlProjectDoc, PAGENAME); RemoveItemsByName(xmlProjectDoc, MARKUPRESOURCENAME); RemoveItemsByName(xmlProjectDoc, RESOURCENAME); // Replace the Reference Item list with ReferencePath RemoveItemsByName(xmlProjectDoc, REFERENCETYPENAME); AddNewItems(xmlProjectDoc, ReferencePathTypeName, ReferencePath); // Add GeneratedCodeFiles to Compile item list. AddNewItems(xmlProjectDoc, CompileTypeName, GeneratedCodeFiles); // Create a random file name // This can fix the problem of project cache in VS.NET environment. // // GetRandomFileName( ) could return any possible file name and extension, but // some file externsion has special meaning in MSBUILD system, such as a ".sln" // means the file is a solution file with special file format. Since the temporary // file is just for a project, we can use a fixed extension here, but the basic // file name is still random which can fix above VS.NET string randProj = Path.ChangeExtension(Path.GetRandomFileName(), TEMP_PROJ_EXT); // Save the xmlDocument content into the temporary project file. xmlProjectDoc.Save(randProj); // // Invoke MSBUILD engine to build this temporary project file. // Hashtable globalProperties = new Hashtable(2); // Add AssemblyName and IntermediateOutputPath to the global property list globalProperties[intermediateOutputPathPropertyName] = IntermediateOutputPath; globalProperties[assemblyNamePropertyName] = AssemblyName; retValue = BuildEngine.BuildProjectFile(randProj, new string[] { CompileTargetName }, globalProperties, null); try { // Delete the random project file from disk. File.Delete(randProj); } catch (IOException e) { // Failure to delete the file is a non fatal error Log.LogWarningFromException(e); } } #pragma warning disable 6500 catch (Exception e) { Log.LogErrorFromException(e); retValue = false; } #pragma warning retore 6500 return(retValue); }