public void VerifyInvalidSchemaItself2() { string invalidSchemaFile = null; string projectFilename = null; string oldValueForMSBuildOldOM = null; string oldValueForMSBuildLoadMicrosoftTargetsReadOnly = Environment.GetEnvironmentVariable("MSBuildLoadMicrosoftTargetsReadOnly"); try { oldValueForMSBuildOldOM = Environment.GetEnvironmentVariable("MSBuildOldOM"); Environment.SetEnvironmentVariable("MSBuildOldOM", ""); // Create schema files in the temp folder invalidSchemaFile = FileUtilities.GetTemporaryFile(); File.WriteAllText(invalidSchemaFile, @"<?xml version=""1.0"" encoding=""UTF-8""?> <xs:schema targetNamespace=""http://schemas.microsoft.com/developer/msbuild/2003"" xmlns:msb=""http://schemas.microsoft.com/developer/msbuild/2003"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" elementFormDefault=""qualified""> <xs:element name=""Project""> <xs:complexType> <xs:sequence> <xs:group ref=""x"" minOccurs=""0"" maxOccurs=""unbounded""/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> "); projectFilename = CreateTempFileOnDisk(@" <Project xmlns=`msbuildnamespace`> <Target Name=`Build` /> </Project> "); string quotedProjectFile = "\"" + projectFilename + "\""; Assert.Equal(MSBuildApp.ExitType.InitializationError, MSBuildApp.Execute(@"c:\foo\msbuild.exe " + quotedProjectFile + " /validate:\"" + invalidSchemaFile + "\"")); } finally { if (invalidSchemaFile != null) { File.Delete(invalidSchemaFile); } if (projectFilename != null) { File.Delete(projectFilename); } Environment.SetEnvironmentVariable("MSBuildOldOM", oldValueForMSBuildOldOM); Environment.SetEnvironmentVariable("MSBuildLoadMicrosoftTargetsReadOnly", oldValueForMSBuildLoadMicrosoftTargetsReadOnly); } }
static int Main() { var paths = new XABuildPaths(); try { if (!Directory.Exists(paths.XamarinAndroidBuildOutput)) { Console.WriteLine($"Unable to find Xamarin.Android build output at {paths.XamarinAndroidBuildOutput}"); return(1); } //Create a custom xabuild.exe.config var xml = CreateConfig(paths); //Create link to .NETFramework and .NETPortable directory foreach (var dir in Directory.GetDirectories(paths.SystemProfiles)) { var name = Path.GetFileName(dir); if (!SymbolicLink.Create(Path.Combine(paths.FrameworksDirectory, name), dir)) { return(1); } } int exitCode = MSBuildApp.Main(); if (exitCode != 0) { Console.WriteLine($"MSBuildApp.Main exited with {exitCode}, xabuild configuration is:"); var settings = new XmlWriterSettings { Indent = true, NewLineOnAttributes = true, }; using (var writer = XmlTextWriter.Create(Console.Out, settings)) { xml.WriteTo(writer); } } return(exitCode); } finally { //NOTE: these are temporary files foreach (var file in new [] { paths.MSBuildExeTempPath, paths.XABuildConfig }) { if (File.Exists(file)) { File.Delete(file); } } } }
private string RunProject(string aProjectFile, string aParams, bool aSuccessFullBuild) { // create a writer to save command line output MyTextWriter lMyWriter = new MyTextWriter(); // set it so the output goes to my writer Console.SetOut(lMyWriter); // get current dir string lBinDir = System.IO.Directory.GetCurrentDirectory(); // create full path to project string lProjectFile = System.IO.Directory.GetCurrentDirectory() + @"\Project\" + aProjectFile; string lProjPath = Path.GetDirectoryName(lProjectFile); // change dir to that project Directory.SetCurrentDirectory(lProjPath); string lproj = Directory.GetCurrentDirectory(); if (lproj == "") { throw new Exception(); } MSBuildApp.ExitType lExitType; try { // use MSBuild class found in MSBuild.EXE assembly lExitType = MSBuildApp.Execute("file " + lProjectFile + " " + aParams); } finally { Directory.SetCurrentDirectory(lBinDir); } // get the text of the MSBuild execution string s = lMyWriter.Text; // save it to a file in the folder using (StreamWriter lWriter = new StreamWriter(lBinDir + "\\MSBuild.log")) lWriter.Write(s); // check to see if there was any errors. if (aSuccessFullBuild) { if (lExitType != MSBuildApp.ExitType.Success) { throw new Exception(s); } } return(s); }
public void VerifyInvalidImportNotCaughtBySchema() { string oldValueForMSBuildLoadMicrosoftTargetsReadOnly = Environment.GetEnvironmentVariable("MSBuildLoadMicrosoftTargetsReadOnly"); string[] msbuildTempXsdFilenames = Array.Empty <string>(); string importedProjectFilename = CreateTempFileOnDisk(@" <Project xmlns=`msbuildnamespace`> <PropertyGroup><UnknownProperty/></PropertyGroup> <Target Name=`Build` /> </Project> "); string projectFilename = CreateTempFileOnDisk(@" <Project xmlns=`msbuildnamespace`> <Import Project=`{0}` /> </Project> ", importedProjectFilename); string oldValueForMSBuildOldOM = null; try { oldValueForMSBuildOldOM = Environment.GetEnvironmentVariable("MSBuildOldOM"); Environment.SetEnvironmentVariable("MSBuildOldOM", ""); // Create schema files in the temp folder msbuildTempXsdFilenames = PrepareSchemaFiles(); string quotedProjectFile = "\"" + projectFilename + "\""; Assert.Equal(MSBuildApp.ExitType.Success, MSBuildApp.Execute(@"c:\foo\msbuild.exe " + quotedProjectFile + " /validate:\"" + msbuildTempXsdFilenames[0] + "\"")); // ProjectSchemaValidationHandler.VerifyProjectSchema // ( // projectFilename, // msbuildTempXsdFilenames[0], // @"c:\" // ); } finally { CleanupSchemaFiles(msbuildTempXsdFilenames); File.Delete(projectFilename); File.Delete(importedProjectFilename); Environment.SetEnvironmentVariable("MSBuildOldOM", oldValueForMSBuildOldOM); Environment.SetEnvironmentVariable("MSBuildLoadMicrosoftTargetsReadOnly", oldValueForMSBuildLoadMicrosoftTargetsReadOnly); } }
public void VerifyInvalidSchemaItself1 ( ) { string invalidSchemaFile = null; string projectFilename = null; string oldValueForMSBuildOldOM = null; try { oldValueForMSBuildOldOM = Environment.GetEnvironmentVariable("MSBuildOldOM"); Environment.SetEnvironmentVariable("MSBuildOldOM", ""); // Create schema files in the temp folder invalidSchemaFile = FileUtilities.GetTemporaryFile(); File.WriteAllText(invalidSchemaFile, "<this_is_invalid_schema_content/>"); projectFilename = CreateTempFileOnDisk(@" <Project xmlns=`msbuildnamespace`> <Target Name=`Build` /> </Project> "); string quotedProjectFile = "\"" + projectFilename + "\""; Assert.Equal(MSBuildApp.ExitType.InitializationError, MSBuildApp.Execute(@"c:\foo\msbuild.exe " + quotedProjectFile + " /validate:\"" + invalidSchemaFile + "\"")); } finally { if (projectFilename != null) { File.Delete(projectFilename); } if (invalidSchemaFile != null) { File.Delete(invalidSchemaFile); } Environment.SetEnvironmentVariable("MSBuildOldOM", oldValueForMSBuildOldOM); } }
protected override void ProcessRecord() { WriteDebug("Process record"); var globalProperties = Property?.Cast <DictionaryEntry>().ToDictionary(x => x.Key.ToString(), x => x.Value.ToString()); globalProperties = globalProperties ?? new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); var projects = string.IsNullOrEmpty(Project) ? new[] { SessionState.Path.CurrentFileSystemLocation.Path } : new[] { Project }; var projectFile = MSBuildApp.ProcessProjectSwitch(projects, IgnoreProjectExtensions, Directory.GetFiles); if (!string.IsNullOrEmpty(Configuration)) { globalProperties[nameof(Configuration)] = Configuration; } if (!string.IsNullOrEmpty(Platform)) { globalProperties[nameof(Platform)] = Platform; } string outputFile = null; if (!string.IsNullOrEmpty(OutputFile)) { outputFile = Path.GetFullPath(Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, OutputFile)); } if (FileUtilities.IsSolutionFilename(projectFile)) { PreprocessSolution(projectFile, globalProperties, ToolsVersion, outputFile); } else { PreprocessProject(projectFile, globalProperties, ToolsVersion, outputFile); } }
public void VerifyInvalidProjectSchema ( ) { string[] msbuildTempXsdFilenames = new string[] { }; string projectFilename = null; string oldValueForMSBuildOldOM = null; try { oldValueForMSBuildOldOM = Environment.GetEnvironmentVariable("MSBuildOldOM"); Environment.SetEnvironmentVariable("MSBuildOldOM", ""); // Create schema files in the temp folder msbuildTempXsdFilenames = PrepareSchemaFiles(); projectFilename = CreateTempFileOnDisk(@" <Project xmlns=`msbuildnamespace`> <PropertyGroup> <MyInvalidProperty/> </PropertyGroup> <Target Name=`Build` /> </Project> "); string quotedProjectFilename = "\"" + projectFilename + "\""; Assert.Equal(MSBuildApp.ExitType.InitializationError, MSBuildApp.Execute(@"c:\foo\msbuild.exe " + quotedProjectFilename + " /validate:\"" + msbuildTempXsdFilenames[0] + "\"")); } finally { if (projectFilename != null) { File.Delete(projectFilename); } CleanupSchemaFiles(msbuildTempXsdFilenames); Environment.SetEnvironmentVariable("MSBuildOldOM", oldValueForMSBuildOldOM); } }
public void VerifyValidProjectSchema ( ) { string[] msbuildTempXsdFilenames = new string[] { }; string projectFilename = CreateTempFileOnDisk(@" <Project xmlns=`msbuildnamespace`> <Target Name=`Build` /> </Project> "); string oldValueForMSBuildOldOM = null; try { oldValueForMSBuildOldOM = Environment.GetEnvironmentVariable("MSBuildOldOM"); Environment.SetEnvironmentVariable("MSBuildOldOM", ""); // Create schema files in the temp folder msbuildTempXsdFilenames = PrepareSchemaFiles(); string quotedProjectFile = "\"" + projectFilename + "\""; Assert.Equal(MSBuildApp.ExitType.Success, MSBuildApp.Execute(@"c:\foo\msbuild.exe " + quotedProjectFile + " /validate:\"" + msbuildTempXsdFilenames[0] + "\"")); //ProjectSchemaValidationHandler.VerifyProjectSchema // ( // projectFilename, // msbuildTempXsdFilenames[0], // @"c:\" // ); } finally { File.Delete(projectFilename); CleanupSchemaFiles(msbuildTempXsdFilenames); Environment.SetEnvironmentVariable("MSBuildOldOM", oldValueForMSBuildOldOM); } }
static int Main() { var paths = new XABuildPaths(); try { if (!Directory.Exists(paths.XamarinAndroidBuildOutput)) { Console.WriteLine($"Unable to find Xamarin.Android build output at {paths.XamarinAndroidBuildOutput}"); return(1); } //Create a custom xabuild.exe.config CreateConfig(paths); //Create link to .NETFramework and .NETPortable directory foreach (var dir in Directory.GetDirectories(paths.SystemProfiles)) { var name = Path.GetFileName(dir); if (!SymbolicLink.Create(Path.Combine(paths.FrameworksDirectory, name), dir)) { return(1); } } return(MSBuildApp.Main()); } finally { //NOTE: these are temporary files foreach (var file in new [] { paths.MSBuildExeTempPath, paths.XABuildConfig }) { if (File.Exists(file)) { File.Delete(file); } } } }
public IEnumerable <CompletionResult> CompleteArgument( string commandName, string parameterName, string wordToComplete, CommandAst commandAst, IDictionary fakeBoundParameters) { var property = GetParameter <Hashtable>(fakeBoundParameters, nameof(InvokeMSBuild.Property)); var toolsVersion = GetParameter <string>(fakeBoundParameters, nameof(InvokeMSBuild.ToolsVersion)); var projectPath = GetParameter <string>(fakeBoundParameters, nameof(InvokeMSBuild.Project)); var ignoreProjectExtensions = GetParameter <string[]>(fakeBoundParameters, nameof(InvokeMSBuild.IgnoreProjectExtensions)); var target = GetParameter <string[]>(fakeBoundParameters, nameof(InvokeMSBuild.Target)); var configuration = GetParameter <string>(fakeBoundParameters, nameof(InvokeMSBuild.Configuration)); var platform = GetParameter <string>(fakeBoundParameters, nameof(InvokeMSBuild.Platform)); var properties = property?.Cast <DictionaryEntry>().ToDictionary(x => x.Key.ToString(), x => x.Value.ToString(), StringComparer.OrdinalIgnoreCase); properties = properties ?? new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); if (!string.IsNullOrEmpty(configuration)) { properties[nameof(InvokeMSBuild.Configuration)] = configuration; } if (!string.IsNullOrEmpty(platform)) { properties[nameof(InvokeMSBuild.Platform)] = platform; } if (string.IsNullOrEmpty(toolsVersion)) { toolsVersion = InvokeMSBuildParameters.DefaultToolsVersion; } var sessionState = new SessionState(); var projects = string.IsNullOrEmpty(projectPath) ? new[] { sessionState.Path.CurrentFileSystemLocation.Path } : new[] { Path.Combine(sessionState.Path.CurrentFileSystemLocation.Path, projectPath) }; var projectFile = MSBuildApp.ProcessProjectSwitch(projects, ignoreProjectExtensions, Directory.GetFiles); var parameters = new InvokeMSBuildParameters { Properties = properties, ToolsVersion = toolsVersion, Project = projectFile, Target = target }; var completionResults = FileUtilities.IsSolutionFilename(projectFile) ? GetSolutionCompletionResults(parameters) : GetProjectCompletionResults(parameters); if (!string.IsNullOrEmpty(wordToComplete)) { completionResults = completionResults.Where(x => x.StartsWith(wordToComplete, StringComparison.InvariantCultureIgnoreCase)); } return(completionResults .OrderBy(x => x) .Select(x => new CompletionResult(EscapeIfRequired(x), x, CompletionResultType.ParameterValue, "tool tip")) .ToArray()); }
static int Main() { var paths = new XABuildPaths(); try { if (!Directory.Exists(paths.XamarinAndroidBuildOutput)) { Console.WriteLine($"Unable to find Xamarin.Android build output at {paths.XamarinAndroidBuildOutput}"); return(1); } //Create a custom xabuild.exe.config var xml = CreateConfig(paths); //Create link to .NETFramework and .NETPortable directory foreach (var dir in Directory.GetDirectories(paths.SystemProfiles)) { var name = Path.GetFileName(dir); if (!SymbolicLink.Create(Path.Combine(paths.FrameworksDirectory, name), dir)) { return(1); } //NOTE: on Windows, the NUnit tests can throw IOException when running xabuild in parallel for (int i = 0;; i++) { try { File.AppendAllText(Path.Combine(paths.FrameworksDirectory, ".__sys_links.txt"), name + "\n"); break; } catch (IOException) { if (i == 2) { throw; //Fail after 3 tries } Thread.Sleep(100); } } } int exitCode = MSBuildApp.Main(); if (exitCode != 0) { Console.WriteLine($"MSBuildApp.Main exited with {exitCode}, xabuild configuration is:"); var settings = new XmlWriterSettings { Indent = true, NewLineOnAttributes = true, }; using (var writer = XmlTextWriter.Create(Console.Out, settings)) { xml.WriteTo(writer); } } return(exitCode); } finally { //NOTE: these are temporary files foreach (var file in new [] { paths.MSBuildExeTempPath, paths.XABuildConfig }) { if (File.Exists(file)) { File.Delete(file); } } } }
static int Main() { var paths = new XABuildPaths(); try { //HACK: running on Mono, MSBuild cannot resolve System.Reflection.Metadata if (!paths.IsWindows) { AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => { var name = new AssemblyName(args.Name); if (name.Name == "System.Reflection.Metadata") { var path = Path.Combine(paths.MSBuildBin, $"{name.Name}.dll"); return(Assembly.LoadFile(path)); } //Return null, to revert to default .NET behavior return(null); }; } if (!Directory.Exists(paths.XamarinAndroidBuildOutput)) { Console.WriteLine($"Unable to find Xamarin.Android build output at {paths.XamarinAndroidBuildOutput}"); return(1); } // Create a custom xabuild.exe.config CreateConfig(paths); // Create a Microsoft.Build.NuGetSdkResolver.xml CreateSdkResolverConfig(paths); //Symbolic links to be created: key=in-tree-dir, value=system-dir var symbolicLinks = new Dictionary <string, string> (); if (paths.IsMacOS || paths.IsLinux) { foreach (var dir in Directory.EnumerateDirectories(paths.MonoSystemFrameworkRoot)) { if (Path.GetFileName(dir).EndsWith("-api", StringComparison.OrdinalIgnoreCase)) { var inTreeFramework = Path.Combine(paths.XamarinAndroidBuildOutput, "lib", "xamarin.android", Path.GetFileName(dir)); symbolicLinks [inTreeFramework] = dir; } } } foreach (var dir in Directory.EnumerateDirectories(paths.SystemFrameworks)) { if (Path.GetFileName(dir) != "MonoAndroid") { var inTreeFramework = Path.Combine(paths.FrameworksDirectory, Path.GetFileName(dir)); symbolicLinks [inTreeFramework] = dir; } } foreach (var dir in paths.SystemTargetsDirectories) { var inTreeTargetsDir = Path.Combine(paths.MSBuildExtensionsPath, Path.GetFileName(dir)); if (!symbolicLinks.ContainsKey(inTreeTargetsDir)) { symbolicLinks [inTreeTargetsDir] = dir; continue; } var prevTargetDir = symbolicLinks [inTreeTargetsDir]; symbolicLinks.Remove(inTreeTargetsDir); if (Directory.Exists(inTreeTargetsDir) && SymbolicLink.IsPathSymlink(inTreeTargetsDir)) { Console.WriteLine($"Removing old symlink: {inTreeTargetsDir}"); Directory.Delete(inTreeTargetsDir); } var subTargetDirs = Directory.EnumerateDirectories(prevTargetDir) .Concat(Directory.EnumerateDirectories(dir)); foreach (var subDir in subTargetDirs) { var inTreeTargetSubdir = Path.Combine(inTreeTargetsDir, Path.GetFileName(subDir)); symbolicLinks [inTreeTargetSubdir] = subDir; } } if (symbolicLinks.Keys.Any(d => !Directory.Exists(d))) { //Hold open the file while creating the symbolic links using (var writer = OpenSysLinksFile(paths)) { foreach (var pair in symbolicLinks) { var systemDirectory = pair.Value; var symbolicLink = pair.Key; Console.WriteLine($"[xabuild] creating symbolic link '{symbolicLink}' -> '{systemDirectory}'"); if (!SymbolicLink.Create(symbolicLink, systemDirectory)) { return(1); } writer.WriteLine(Path.GetFileName(symbolicLink)); } } } return(MSBuildApp.Main()); } finally { //NOTE: this is a temporary directory Directory.Delete(paths.MSBuildTempPath, recursive: true); } }
static int Main() { var paths = new XABuildPaths(); try { if (!Directory.Exists(paths.XamarinAndroidBuildOutput)) { Console.WriteLine($"Unable to find Xamarin.Android build output at {paths.XamarinAndroidBuildOutput}"); return(1); } //Create a custom xabuild.exe.config var xml = CreateConfig(paths); //Symbolic links to .NETFramework and .NETPortable directory var systemDirectories = Directory.EnumerateDirectories(paths.SystemProfiles) .Where(d => Path.GetFileName(d) != "MonoAndroid") //NOTE: this happened on one of our VSTS build agents .ToArray(); var symbolicLinks = systemDirectories .Select(d => Path.Combine(paths.FrameworksDirectory, Path.GetFileName(d))) .ToArray(); if (symbolicLinks.Any(d => !Directory.Exists(d))) { //Hold open the file while creating the symbolic links using (var writer = OpenSysLinksFile(paths)) { for (int i = 0; i < systemDirectories.Length; i++) { var symbolicLink = symbolicLinks [i]; var systemDirectory = systemDirectories [i]; Console.WriteLine($"[xabuild] creating symbolic link '{symbolicLink}' -> '{systemDirectory}'"); if (!SymbolicLink.Create(symbolicLink, systemDirectory)) { return(1); } writer.WriteLine(Path.GetFileName(symbolicLink)); } } } int exitCode = MSBuildApp.Main(); if (exitCode != 0) { Console.WriteLine($"MSBuildApp.Main exited with {exitCode}, xabuild configuration is:"); var settings = new XmlWriterSettings { Indent = true, NewLineOnAttributes = true, }; using (var writer = XmlTextWriter.Create(Console.Out, settings)) { xml.WriteTo(writer); } } return(exitCode); } finally { //NOTE: these are temporary files foreach (var file in new [] { paths.MSBuildExeTempPath, paths.XABuildConfig }) { if (File.Exists(file)) { File.Delete(file); } } } }
protected override void ProcessRecord() { WriteDebug("Process record"); var properties = Property?.Cast <DictionaryEntry>().ToDictionary(x => x.Key.ToString(), x => x.Value.ToString()); properties = properties ?? new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); var projects = string.IsNullOrEmpty(Project) ? new[] { SessionState.Path.CurrentFileSystemLocation.Path } : new[] { Project }; var project = MSBuildApp.ProcessProjectSwitch(projects, IgnoreProjectExtensions, Directory.GetFiles); if (!string.IsNullOrEmpty(Configuration)) { properties[nameof(Configuration)] = Configuration; } if (!string.IsNullOrEmpty(Platform)) { properties[nameof(Platform)] = Platform; } _msBuildHelper.Parameters = new InvokeMSBuildParameters { Project = project, Verbosity = Verbosity, ToolsVersion = ToolsVersion, Target = Target, MaxCpuCount = MaxCpuCount, NodeReuse = NodeReuse ?? Environment.GetEnvironmentVariable("MSBUILDDISABLENODEREUSE") != "1", Properties = properties, DetailedSummary = DetailedSummary || Verbosity == LoggerVerbosity.Diagnostic, WarningsAsErrors = WarningsAsErrors == null ? null : new HashSet <string>(WarningsAsErrors, StringComparer.InvariantCultureIgnoreCase), WarningsAsMessages = WarningsAsMessages == null ? null : new HashSet <string>(WarningsAsMessages, StringComparer.InvariantCultureIgnoreCase) }; var loggers = new List <ILogger>(); ILogger consoleLogger; if (Logger != null) { loggers.AddRange(Logger); } var consoleLoggerType = GetConsoleLoggerType(); switch (consoleLoggerType) { case ConsoleLoggerType.Streams: consoleLogger = Factory.PowerShellInstance.CreateConsoleLogger(Verbosity, ConsoleLoggerParameters, false); break; case ConsoleLoggerType.PSHost: consoleLogger = Factory.PowerShellInstance.CreateConsoleLogger(Verbosity, ConsoleLoggerParameters, true); break; case ConsoleLoggerType.None: consoleLogger = null; break; default: throw new InvalidEnumArgumentException(); } if (consoleLogger != null) { loggers.Add(consoleLogger); } var eventSink = new PSEventSink(this); foreach (var psLogger in loggers.OfType <IPSLogger>()) { psLogger.Initialize(eventSink); } var crossDomainLoggers = ( from unknownLogger in loggers group unknownLogger by unknownLogger is MarshalByRefObject into marshalByRefLogger from logger in MakeLoggersCrossDomain(marshalByRefLogger.Key, marshalByRefLogger) select logger).ToArray(); _msBuildHelper.Loggers = crossDomainLoggers; try { var asyncResults = ProcessRecordAsync(eventSink); eventSink.ConsumeEvents(); var results = asyncResults.Result; WriteObject(results, true); } catch (Exception ex) { WriteError(new ErrorRecord(ex, "ProcessRecordError", ErrorCategory.NotSpecified, null)); } }
static int Main() { var paths = new XABuildPaths(); try { //HACK: running on Mono, MSBuild cannot resolve System.Reflection.Metadata if (!paths.IsWindows) { AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => { var name = new AssemblyName(args.Name); if (name.Name == "System.Reflection.Metadata") { var path = Path.Combine(paths.MSBuildBin, $"{name.Name}.dll"); return(Assembly.LoadFile(path)); } //Return null, to revert to default .NET behavior return(null); }; } if (!Directory.Exists(paths.XamarinAndroidBuildOutput)) { Console.WriteLine($"Unable to find Xamarin.Android build output at {paths.XamarinAndroidBuildOutput}"); return(1); } //Create a custom xabuild.exe.config var xml = CreateConfig(paths); //Symbolic links to be created: key=system, value=in-tree var symbolicLinks = new Dictionary <string, string> (); foreach (var dir in Directory.EnumerateDirectories(paths.SystemFrameworks)) { if (Path.GetFileName(dir) != "MonoAndroid") { symbolicLinks [dir] = Path.Combine(paths.FrameworksDirectory, Path.GetFileName(dir)); } } foreach (var dir in paths.SystemTargetsDirectories) { symbolicLinks [dir] = Path.Combine(paths.MSBuildExtensionsPath, Path.GetFileName(dir)); } if (symbolicLinks.Values.Any(d => !Directory.Exists(d))) { //Hold open the file while creating the symbolic links using (var writer = OpenSysLinksFile(paths)) { foreach (var pair in symbolicLinks) { var systemDirectory = pair.Key; var symbolicLink = pair.Value; Console.WriteLine($"[xabuild] creating symbolic link '{symbolicLink}' -> '{systemDirectory}'"); if (!SymbolicLink.Create(symbolicLink, systemDirectory)) { return(1); } writer.WriteLine(Path.GetFileName(symbolicLink)); } } } return(MSBuildApp.Main()); } finally { //NOTE: these are temporary files foreach (var file in new [] { paths.MSBuildExeTempPath, paths.XABuildConfig }) { if (File.Exists(file)) { File.Delete(file); } } } }
protected override void ProcessRecord() { WriteDebug("Process record"); var properties = Property?.Cast <DictionaryEntry>().ToDictionary(x => x.Key.ToString(), x => x.Value.ToString()); properties = properties ?? new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); var projects = string.IsNullOrEmpty(Project) ? new[] { SessionState.Path.CurrentFileSystemLocation.Path } : new[] { Project }; var project = MSBuildApp.ProcessProjectSwitch(projects, IgnoreProjectExtensions, Directory.GetFiles); if (!string.IsNullOrEmpty(Configuration)) { properties[nameof(Configuration)] = Configuration; } if (!string.IsNullOrEmpty(Platform)) { properties[nameof(Platform)] = Platform; } _msBuildHelper.Parameters = new InvokeMSBuildParameters { Project = project, Verbosity = Verbosity, ToolsVersion = ToolsVersion, Target = Target, MaxCpuCount = MaxCpuCount, NodeReuse = NodeReuse ?? Environment.GetEnvironmentVariable("MSBUILDDISABLENODEREUSE") != "1", Properties = properties, DetailedSummary = DetailedSummary || Verbosity == LoggerVerbosity.Diagnostic, WarningsAsErrors = WarningsAsErrors == null ? null : new HashSet <string>(WarningsAsErrors, StringComparer.InvariantCultureIgnoreCase), WarningsAsMessages = WarningsAsMessages == null ? null : new HashSet <string>(WarningsAsMessages, StringComparer.InvariantCultureIgnoreCase) }; var loggers = new List <LoggerDescription>(); LoggerDescription consoleLogger; if (Logger != null) { loggers.AddRange(Logger); } var consoleLoggerType = GetConsoleLoggerType(); switch (consoleLoggerType) { case ConsoleLoggerType.PSStreams: consoleLogger = new LoggerDescription { Assembly = NewConsoleLogger.Assembly, ClassName = NewConsoleLogger.PSStreamsLoggerClassName, Parameters = ConsoleLoggerParameters, Verbosity = Verbosity }; break; case ConsoleLoggerType.PSHost: consoleLogger = new LoggerDescription { Assembly = NewConsoleLogger.Assembly, ClassName = NewConsoleLogger.PSHostLoggerClassName, Parameters = ConsoleLoggerParameters, Verbosity = Verbosity }; break; case ConsoleLoggerType.None: consoleLogger = null; break; default: throw new InvalidEnumArgumentException(); } if (consoleLogger != null) { loggers.Add(consoleLogger); } var eventSink = _msBuildHelper.PSEventSink = new PSEventSink(this); _msBuildHelper.Loggers = loggers; try { var asyncResults = ProcessRecordAsync(eventSink); eventSink.ConsumeEvents(); var results = asyncResults.Result; WriteObject(results, true); } catch (Exception ex) { WriteError(new ErrorRecord(ex, "ProcessRecordError", ErrorCategory.NotSpecified, null)); } }