public void GetsProjectGuidFromProject([ValueSource(nameof(Preferences))] EnvironmentPreference preference) { // Given const string projectFile = @"SdkNetCoreProject\SdkNetCoreProject.csproj"; IProjectAnalyzer analyzer = new AnalyzerManager() .GetProject(GetProjectPath(projectFile)); EnvironmentOptions options = new EnvironmentOptions { Preference = preference }; // When DeleteProjectDirectory(projectFile, "obj"); DeleteProjectDirectory(projectFile, "bin"); IAnalyzerResults results = analyzer.Build(options); // Then // The generated GUIDs are based on subpath, so they'll be different from Windows to Linux // They can also change between MSBuild versions, so this may need to be updated periodically #if Is_Windows results.First().ProjectGuid.ToString().ShouldBe("432bfde1-4768-5837-8e20-8bb49c9d4734"); #else results.First().ProjectGuid.ToString().ShouldBe("c9df4376-d954-5554-bd10-b9976b7afa9d"); #endif }
public (IAnalyzerResults AnalyzerResults, BuildOutput Log) Build(string projectFilePath, bool designTime = false) { var projectAnalyzer = new AnalyzerManager().GetProject(projectFilePath); var logger = BuildOutput.Create(); projectAnalyzer.AddBuildLogger(logger); projectAnalyzer.AddBinaryLogger("build.binlog"); var analyzerResults = projectAnalyzer.Build( new EnvironmentOptions() { DesignTime = designTime } ); return(analyzerResults, logger); }
public int Execute() { try { if (!TryFindProject(out var projectFile)) { return(-1); } _logger.LogDebug("Evaluating project {project}", projectFile); var project = new AnalyzerManager().GetProject(projectFile); if (project == null) { throw new InvalidOperationException($"Could not find project {projectFile}."); } var results = project.Build().FirstOrDefault(); if (results == null) { throw new InvalidOperationException("No target frameworks detected."); } var value = results.GetProperty(_options.Name); if (value == null) { throw new InvalidOperationException($"Property {_options.Name} not found for target framework {results.TargetFramework}."); } Console.Write(value); return(0); } #pragma warning disable CA1031 catch (Exception ex) #pragma warning restore { _logger.LogCritical(ex, "Fatal error"); return(-1); } finally { _hostApplicationLifetime.StopApplication(); } }
public void BuildsProjectWithoutLogger([ValueSource(nameof(Preferences))] EnvironmentPreference preference) { // Given const string projectFile = @"SdkNetCore2Project\SdkNetCore2Project.csproj"; IProjectAnalyzer analyzer = new AnalyzerManager() .GetProject(GetProjectPath(projectFile)); EnvironmentOptions options = new EnvironmentOptions { Preference = preference }; // When DeleteProjectDirectory(projectFile, "obj"); DeleteProjectDirectory(projectFile, "bin"); IAnalyzerResults results = analyzer.Build(options); // Then results.Count.ShouldBeGreaterThan(0); results.OverallSuccess.ShouldBeTrue(); results.ShouldAllBe(x => x.Succeeded); }
public void GetsProjectGuidFromProject([ValueSource(nameof(Preferences))] EnvironmentPreference preference) { // Given const string projectFile = @"SdkNetCore2Project\SdkNetCore2Project.csproj"; IProjectAnalyzer analyzer = new AnalyzerManager() .GetProject(GetProjectPath(projectFile)); EnvironmentOptions options = new EnvironmentOptions { Preference = preference }; // When DeleteProjectDirectory(projectFile, "obj"); DeleteProjectDirectory(projectFile, "bin"); IAnalyzerResults results = analyzer.Build(options); // Then // The generated GUIDs are based on subpath and can also change between MSBuild versions, // so this may need to be updated periodically results.First().ProjectGuid.ToString().ShouldBe("1ff50b40-c27b-5cea-b265-29c5436a8a7b"); }
public void GetsProjectGuidFromProject([ValueSource(nameof(Preferences))] EnvironmentPreference preference) { // Given const string projectFile = @"SdkNetCoreProject\SdkNetCoreProject.csproj"; ProjectAnalyzer analyzer = new AnalyzerManager() .GetProject(GetProjectPath(projectFile)); EnvironmentOptions options = new EnvironmentOptions { Preference = preference }; // When DeleteProjectDirectory(projectFile, "obj"); DeleteProjectDirectory(projectFile, "bin"); AnalyzerResults results = analyzer.Build(options); // Then // The generated GUIDs are based on subpath, so they'll be different from Windows to Linux #if Is_Windows results.First().ProjectGuid.ToString().ShouldBe("646a532e-8943-5a4b-b106-e1341b4d3535"); #else results.First().ProjectGuid.ToString().ShouldBe("c9df4376-d954-5554-bd10-b9976b7afa9d"); #endif }