public BuildContext(ICakeContext context) : base(context) { BuildConfiguration = context.Argument("Configuration", "Release"); SkipTests = context.Argument("SkipTests", false); SkipSlowTests = context.Argument("SkipSlowTests", false); RootDirectory = new DirectoryPath(new DirectoryInfo(Directory.GetCurrentDirectory()).Parent.FullName); ArtifactsDirectory = RootDirectory.Combine("artifacts"); ToolsDirectory = RootDirectory.Combine("tools"); DocsDirectory = RootDirectory.Combine("docs"); DocfxDirectory = ToolsDirectory.Combine("docfx"); DocfxExeFile = DocfxDirectory.CombineWithFilePath("docfx.exe"); DocfxJsonFile = DocsDirectory.CombineWithFilePath("docfx.json"); TestOutputDirectory = RootDirectory.Combine("TestResults"); ChangeLogDirectory = RootDirectory.Combine("docs").Combine("changelog"); ChangeLogGenDirectory = RootDirectory.Combine("docs").Combine("_changelog"); SolutionFile = RootDirectory.CombineWithFilePath("BenchmarkDotNet.sln"); UnitTestsProjectFile = RootDirectory.Combine("tests").Combine("BenchmarkDotNet.Tests") .CombineWithFilePath("BenchmarkDotNet.Tests.csproj"); IntegrationTestsProjectFile = RootDirectory.Combine("tests").Combine("BenchmarkDotNet.IntegrationTests") .CombineWithFilePath("BenchmarkDotNet.IntegrationTests.csproj"); TemplatesTestsProjectFile = RootDirectory.Combine("templates") .CombineWithFilePath("BenchmarkDotNet.Templates.csproj"); AllPackableSrcProjects = new FilePathCollection(context.GetFiles(RootDirectory.FullPath + "/src/**/*.csproj") .Where(p => !p.FullPath.Contains("Disassembler"))); MsBuildSettings = new DotNetCoreMSBuildSettings { MaxCpuCount = 1 }; MsBuildSettings.WithProperty("UseSharedCompilation", "false"); }
public BuildContext(ICakeContext context) : base(context) { BuildConfiguration = context.Argument("Configuration", "Release"); SkipTests = context.Argument("SkipTests", false); SkipSlowTests = context.Argument("SkipSlowTests", false); RootDirectory = new DirectoryPath(new DirectoryInfo(Directory.GetCurrentDirectory()).Parent.FullName); ArtifactsDirectory = RootDirectory.Combine("artifacts"); ToolsDirectory = RootDirectory.Combine("tools"); DocsDirectory = RootDirectory.Combine("docs"); DocfxDirectory = ToolsDirectory.Combine("docfx"); DocfxExeFile = DocfxDirectory.CombineWithFilePath("docfx.exe"); DocfxJsonFile = DocsDirectory.CombineWithFilePath("docfx.json"); TestOutputDirectory = RootDirectory.Combine("TestResults"); ChangeLogDirectory = RootDirectory.Combine("docs").Combine("changelog"); ChangeLogGenDirectory = RootDirectory.Combine("docs").Combine("_changelog"); SolutionFile = RootDirectory.CombineWithFilePath("BenchmarkDotNet.sln"); UnitTestsProjectFile = RootDirectory.Combine("tests").Combine("BenchmarkDotNet.Tests") .CombineWithFilePath("BenchmarkDotNet.Tests.csproj"); IntegrationTestsProjectFile = RootDirectory.Combine("tests").Combine("BenchmarkDotNet.IntegrationTests") .CombineWithFilePath("BenchmarkDotNet.IntegrationTests.csproj"); TemplatesTestsProjectFile = RootDirectory.Combine("templates") .CombineWithFilePath("BenchmarkDotNet.Templates.csproj"); AllPackableSrcProjects = new FilePathCollection(context.GetFiles(RootDirectory.FullPath + "/src/**/*.csproj") .Where(p => !p.FullPath.Contains("Disassembler"))); MsBuildSettings = new DotNetCoreMSBuildSettings { MaxCpuCount = 1 }; MsBuildSettings.WithProperty("UseSharedCompilation", "false"); // NativeAOT build requires VS C++ tools to be added to $path via vcvars64.bat // but once we do that, dotnet restore fails with: // "Please specify a valid solution configuration using the Configuration and Platform properties" if (context.IsRunningOnWindows()) { MsBuildSettings.WithProperty("Platform", "Any CPU"); } }
protected override int Execute() { var thisAssembly = typeof(GetDocumentCommand).Assembly; var toolsDirectory = ToolsDirectory.Value(); var packagedAssemblies = Directory .EnumerateFiles(toolsDirectory, "*.dll") .Except(new[] { Path.GetFullPath(thisAssembly.Location) }) .ToDictionary(path => Path.GetFileNameWithoutExtension(path), path => new AssemblyInfo(path)); // Explicitly load all assemblies we need first to preserve target project as much as possible. This // executable is always run in the target project's context (either through location or .deps.json file). foreach (var keyValuePair in packagedAssemblies) { try { keyValuePair.Value.Assembly = Assembly.Load(new AssemblyName(keyValuePair.Key)); } catch { // Ignore all failures because missing assemblies should be loadable from tools directory. } } #if NETCOREAPP2_1 AssemblyLoadContext.Default.Resolving += (loadContext, assemblyName) => { var name = assemblyName.Name; if (!packagedAssemblies.TryGetValue(name, out var info)) { return(null); } var assemblyPath = info.Path; if (!File.Exists(assemblyPath)) { throw new InvalidOperationException( $"Referenced assembly '{name}' was not found in '{toolsDirectory}'."); } return(loadContext.LoadFromAssemblyPath(assemblyPath)); }; #elif NETFRAMEWORK AppDomain.CurrentDomain.AssemblyResolve += (source, eventArgs) => { var assemblyName = new AssemblyName(eventArgs.Name); var name = assemblyName.Name; if (!packagedAssemblies.TryGetValue(name, out var info)) { return(null); } var assembly = info.Assembly; if (assembly != null) { // Loaded already return(assembly); } var assemblyPath = info.Path; if (!File.Exists(assemblyPath)) { throw new InvalidOperationException( $"Referenced assembly '{name}' was not found in '{toolsDirectory}'."); } return(Assembly.LoadFile(assemblyPath)); }; #else #error Target frameworks need to be updated. #endif // Now safe to reference the application's code. try { var assemblyPath = AssemblyPath.Value(); var context = new GetDocumentCommandContext { AssemblyPath = assemblyPath, AssemblyName = Path.GetFileNameWithoutExtension(assemblyPath), FileListPath = _fileListPath.Value(), OutputDirectory = _output.Value(), ProjectName = ProjectName.Value(), Reporter = Reporter, }; return(new GetDocumentCommandWorker(context).Process()); } catch (Exception ex) { Reporter.WriteError(ex.ToString()); return(2); } }