Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live logger properly report errors during restore. #8707

Merged
merged 17 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
Expand Down
10 changes: 7 additions & 3 deletions documentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ The folder contains collection of docs and references for MSBuild, detailed info
* [Target maps](wiki/Target-Maps.md)
* [Managing parallelism in MSBuild](specs/resource-management.md)
* [SDK resolution](specs/sdk-resolvers-algorithm.md)
* [RAR core scenarios](specs/rar-core-scenarios.md)

### Tasks

Expand All @@ -75,11 +76,14 @@ The folder contains collection of docs and references for MSBuild, detailed info
* [Binary log](wiki/Binary-Log.md)
* [Live logger: how to opt in](livelogger/Opt-In-Mechanism.md)

## Designs

* [Resolve Assembly Reference as a service](design/rar-as-service.md)
## Archived Designs
* [Resolve Assembly Reference as a service](specs/rar-as-service.md)
* Prototype: https://github.com/dotnet/msbuild/issues/6193

## Proposed Designs
* [Packages Sourcing](specs/proposed/interactive-package-references.md)
* [Secrets Metadata](specs/proposed/security-metadata.md)

## Community contributions

* [MSBuild overview](Contributions/MSBuild-overview.md)
Expand Down
22 changes: 19 additions & 3 deletions documentation/wiki/Providing-Binary-Logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,37 @@ However, you should be aware what type of information is captured in the binary

⚠ NOTE: some build environments make secrets available using environment variables. Before sharing a binary log, make sure it does not expose API tokens or other important secrets.

## Capturing Binary Logs for command-line builds

You can create a binary log by passing the `-bl` parameter to MSBuild (`MSBuild.exe` or `dotnet build`). You can explore the contents of the generated .binlog file using [MSBuild Structured Log Viewer](http://msbuildlog.com/) or in your browser using [Live Structured Log Viewer](https://live.msbuildlog.com). Note: We don't capture any data from binary logs viewed on your browser.

Examples:

```sh
dotnet build -bl
dotnet build -bl:SpecificStep.binlog
MSBuild.exe -bl:ServiceRelease.binlog -p:Configuration=Release
```

[More details about binary logs](Binary-Log.md)

## Capturing Binary Logs Through Visual Studio
### (Preferred way) Capturing logs for all MSBuild invocations

### Capturing logs for all MSBuild invocations

Set `MSBUILDDEBUGENGINE` environment variable to `'1'` and (optionally) set `MSBUILDDEBUGPATH` to an existing destination folder to store the captured logs. Then start Visual Studio from the same shell to inherit the environment:

`cmd:`
```

```batch
> SET MSBUILDDEBUGENGINE=1
> SET MSBUILDDEBUGPATH=C:\MSBuildReproLogs
> devenv.exe MySolution.sln
```

`PowerShell:`
```

```powershell
> $env:MSBUILDDEBUGENGINE = 1
> $env:MSBUILDDEBUGPATH="C:\MSBuildReproLogs"
> & "devenv.exe" MySolution.sln
Expand All @@ -33,8 +47,10 @@ MSBuild binary logs are then captured to a location specified via `MSBUILDDEBUGP
⚠ NOTE: logs are being recorded for each MSBuild invocation (including design time builds) and kept in the folder without removing older ones - so the number of log files can grow quickly. It is recommended to set the opt-in environment variable only for the short duration of reproducing the issue to be investigated (though it is understandable that some nondeterministic issues might need multiple reproduction attempts)

Further reading:

* [More technical info](Building-Testing-and-Debugging-on-Full-Framework-MSBuild.md#logs)
* [Design time builds logs](https://github.com/dotnet/project-system/blob/main/docs/repo/debugging/design-time-builds.md#gathering-full-fidelity-binlogs)

### Capturing specific logs for chosen build invocations

See [this guide](https://github.com/dotnet/project-system-tools) in the Project System Tools repo for capturing binlogs through Visual Studio.
4 changes: 2 additions & 2 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
<Sha>bc3233146e1fcd393ed471d5005333c83363e0fe</Sha>
<SourceBuild RepoName="xliff-tasks" ManagedOnly="true" />
</Dependency>
<Dependency Name="NuGet.Build.Tasks" Version="6.7.0-preview.1.16">
<Dependency Name="NuGet.Build.Tasks" Version="6.7.0-preview.1.20">
<Uri>https://github.com/nuget/nuget.client</Uri>
<Sha>7eaba9f3f68b8df63d5dcf10e2a8ef3591164ddf</Sha>
<Sha>f1757fe7a9a3e178562518f4535f71348a117010</Sha>
</Dependency>
<Dependency Name="Microsoft.Net.Compilers.Toolset" Version="4.6.0-2.23171.5">
<Uri>https://github.com/dotnet/roslyn</Uri>
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<MicrosoftExtensionsDependencyModelVersion>7.0.0</MicrosoftExtensionsDependencyModelVersion>
<MicrosoftIORedistVersion>6.0.0</MicrosoftIORedistVersion>
<MicrosoftNetCompilersToolsetVersion>4.6.0-2.23171.5</MicrosoftNetCompilersToolsetVersion>
<NuGetBuildTasksVersion>6.7.0-preview.1.16</NuGetBuildTasksVersion>
<NuGetBuildTasksVersion>6.7.0-preview.1.20</NuGetBuildTasksVersion>
<SystemRuntimeCompilerServicesUnsafeVersion>6.0.0</SystemRuntimeCompilerServicesUnsafeVersion>
<SystemTextJsonVersion>7.0.0</SystemTextJsonVersion>
<SystemThreadingTasksDataflowVersion>7.0.0</SystemThreadingTasksDataflowVersion>
Expand Down
15 changes: 15 additions & 0 deletions src/Build.UnitTests/Graph/GraphLoadedFromSolution_tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.Build.BackEnd;
using Microsoft.Build.Collections;
using Microsoft.Build.Construction;
using Microsoft.Build.Engine.UnitTests;
using Microsoft.Build.Exceptions;
Expand Down Expand Up @@ -523,6 +524,20 @@ public void SolutionsCanInjectEdgesIntoTheProjectGraph(Dictionary<int, int[]> ed

var graphFromSolutionEdges = graphFromSolution.TestOnly_Edges.TestOnly_AsConfigurationMetadata();

// Solutions add the CurrentSolutionConfigurationContents global property for platform resolution
foreach ((ConfigurationMetadata, ConfigurationMetadata) graphFromSolutionEdge in graphFromSolutionEdges.Keys)
{
graphFromSolutionEdge.Item1.GlobalProperties.ShouldContainKey("CurrentSolutionConfigurationContents");
graphFromSolutionEdge.Item2.GlobalProperties.ShouldContainKey("CurrentSolutionConfigurationContents");
}

// Remove CurrentSolutionConfigurationContents for comparison purposes. This is done as a separate pass since some edges may be sharing an instance.
foreach ((ConfigurationMetadata, ConfigurationMetadata) graphFromSolutionEdge in graphFromSolutionEdges.Keys)
{
graphFromSolutionEdge.Item1.GlobalProperties.Remove("CurrentSolutionConfigurationContents");
graphFromSolutionEdge.Item2.GlobalProperties.Remove("CurrentSolutionConfigurationContents");
}

// Original edges get preserved.
foreach (var graphEdge in graphEdges)
{
Expand Down
125 changes: 125 additions & 0 deletions src/Build.UnitTests/Graph/ProjectGraph_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.Build.Construction;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Exceptions;
using Microsoft.Build.Execution;
Expand Down Expand Up @@ -674,6 +675,130 @@ public void ConstructGraphWithDifferentEntryPointsAndGraphRoots()
}
}

[Fact]
public void ConstructGraphWithSolution()
{
// This test exercises two key features of solution-based builds from AssignProjectConfiguration:
// 1. Adding synthetic project references
// 2. Resolving project configuration based on the sln
using (var env = TestEnvironment.Create())
{
const string SolutionFileContents = """
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 17.0.31903.59
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Project1", "Project1.csproj", "{8761499A-7280-43C4-A32F-7F41C47CA6DF}"
ProjectSection(ProjectDependencies) = postProject
{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98} = {52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Project2", "Project2.vcxproj", "{D638A8EF-3A48-45F2-913C-88B29FED03CB}"
EndProject
Project("{13B669BE-BB05-4DDF-9536-439F39A36129}") = "Project3", "Project3.vcxproj", "{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Win32 = Release|Win32
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8761499A-7280-43C4-A32F-7F41C47CA6DF}.Debug|Win32.ActiveCfg = Debug|x86
{8761499A-7280-43C4-A32F-7F41C47CA6DF}.Debug|Win32.Build.0 = Debug|x86
{8761499A-7280-43C4-A32F-7F41C47CA6DF}.Debug|x64.ActiveCfg = Debug|x64
{8761499A-7280-43C4-A32F-7F41C47CA6DF}.Debug|x64.Build.0 = Debug|x64
{8761499A-7280-43C4-A32F-7F41C47CA6DF}.Debug|x86.ActiveCfg = Debug|x86
{8761499A-7280-43C4-A32F-7F41C47CA6DF}.Debug|x86.Build.0 = Debug|x86
{8761499A-7280-43C4-A32F-7F41C47CA6DF}.Release|Win32.ActiveCfg = Release|x86
{8761499A-7280-43C4-A32F-7F41C47CA6DF}.Release|Win32.Build.0 = Release|x86
{8761499A-7280-43C4-A32F-7F41C47CA6DF}.Release|x64.ActiveCfg = Release|x64
{8761499A-7280-43C4-A32F-7F41C47CA6DF}.Release|x64.Build.0 = Release|x64
{8761499A-7280-43C4-A32F-7F41C47CA6DF}.Release|x86.ActiveCfg = Release|x86
{8761499A-7280-43C4-A32F-7F41C47CA6DF}.Release|x86.Build.0 = Release|x86
{D638A8EF-3A48-45F2-913C-88B29FED03CB}.Debug|Win32.ActiveCfg = Debug|Win32
{D638A8EF-3A48-45F2-913C-88B29FED03CB}.Debug|Win32.Build.0 = Debug|Win32
{D638A8EF-3A48-45F2-913C-88B29FED03CB}.Debug|x64.ActiveCfg = Debug|x64
{D638A8EF-3A48-45F2-913C-88B29FED03CB}.Debug|x64.Build.0 = Debug|x64
{D638A8EF-3A48-45F2-913C-88B29FED03CB}.Release|Win32.ActiveCfg = Release|Win32
{D638A8EF-3A48-45F2-913C-88B29FED03CB}.Release|Win32.Build.0 = Release|Win32
{D638A8EF-3A48-45F2-913C-88B29FED03CB}.Release|x64.ActiveCfg = Release|x64
{D638A8EF-3A48-45F2-913C-88B29FED03CB}.Release|x64.Build.0 = Release|x64
{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}.Debug|Win32.ActiveCfg = Debug|Win32
{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}.Debug|Win32.Build.0 = Debug|Win32
{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}.Debug|x64.ActiveCfg = Debug|x64
{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}.Debug|x64.Build.0 = Debug|x64
{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}.Debug|x86.ActiveCfg = Debug|Win32
{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}.Debug|x86.Build.0 = Debug|Win32
{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}.Release|Win32.ActiveCfg = Release|Win32
{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}.Release|Win32.Build.0 = Release|Win32
{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}.Release|x64.ActiveCfg = Release|x64
{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}.Release|x64.Build.0 = Release|x64
{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}.Release|x86.ActiveCfg = Release|Win32
{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}.Release|x86.Build.0 = Release|Win32
{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}.Debug|Win32.ActiveCfg = Debug|Win32
{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}.Debug|Win32.Build.0 = Debug|Win32
{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}.Debug|x64.ActiveCfg = Debug|x64
{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}.Debug|x64.Build.0 = Debug|x64
{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}.Debug|x86.ActiveCfg = Debug|Win32
{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}.Debug|x86.Build.0 = Debug|Win32
{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}.Release|Win32.ActiveCfg = Release|Win32
{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}.Release|Win32.Build.0 = Release|Win32
{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}.Release|x64.ActiveCfg = Release|x64
{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}.Release|x64.Build.0 = Release|x64
{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}.Release|x86.ActiveCfg = Release|Win32
{52B2ED64-1CFC-401B-8C5B-6D1E1DEADF98}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
""";
TransientTestFile slnFile = env.CreateFile(@"Solution.sln", SolutionFileContents);
SolutionFile solutionFile = SolutionFile.Parse(slnFile.Path);

ProjectRootElement project1Xml = ProjectRootElement.Create();

// Project 1 depends on Project 2 using ProjectReference but there is a sln-based dependency defined on Project 3 as well.
project1Xml.AddItem("ProjectReference", "Project2.vcxproj");

ProjectRootElement project2Xml = ProjectRootElement.Create();
ProjectRootElement project3Xml = ProjectRootElement.Create();

string project1Path = Path.Combine(env.DefaultTestDirectory.Path, "Project1.csproj");
string project2Path = Path.Combine(env.DefaultTestDirectory.Path, "Project2.vcxproj");
string project3Path = Path.Combine(env.DefaultTestDirectory.Path, "Project3.vcxproj");

project1Xml.Save(project1Path);
project2Xml.Save(project2Path);
project3Xml.Save(project3Path);

var projectGraph = new ProjectGraph(slnFile.Path);
projectGraph.EntryPointNodes.Count.ShouldBe(3);
projectGraph.GraphRoots.Count.ShouldBe(1);
projectGraph.GraphRoots.First().ProjectInstance.FullPath.ShouldBe(project1Path);
projectGraph.ProjectNodes.Count.ShouldBe(3);

ProjectGraphNode project1Node = projectGraph.ProjectNodes.Single(node => node.ProjectInstance.FullPath == project1Path);
project1Node.ProjectInstance.GlobalProperties["Configuration"].ShouldBe("Debug");
project1Node.ProjectInstance.GlobalProperties["Platform"].ShouldBe("x86");
project1Node.ProjectReferences.Count.ShouldBe(2);

ProjectGraphNode project2Node = projectGraph.ProjectNodes.Single(node => node.ProjectInstance.FullPath == project2Path);
project2Node.ProjectInstance.GlobalProperties["Configuration"].ShouldBe("Debug");
project2Node.ProjectInstance.GlobalProperties["Platform"].ShouldBe("Win32");
project2Node.ProjectReferences.Count.ShouldBe(0);

ProjectGraphNode project3Node = projectGraph.ProjectNodes.Single(node => node.ProjectInstance.FullPath == project3Path);
project3Node.ProjectInstance.GlobalProperties["Configuration"].ShouldBe("Debug");
project3Node.ProjectInstance.GlobalProperties["Platform"].ShouldBe("Win32");
project3Node.ProjectReferences.Count.ShouldBe(0);
}
}

[Fact]
public void GetTargetListsAggregatesFromMultipleEdges()
{
Expand Down
32 changes: 19 additions & 13 deletions src/Build/Construction/Solution/SolutionProjectGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,23 @@ internal static void AddPropertyGroupForSolutionConfiguration(ProjectRootElement
msbuildProject.AppendChild(solutionConfigurationProperties);
solutionConfigurationProperties.Condition = GetConditionStringForConfiguration(solutionConfiguration);

string escapedSolutionConfigurationContents = GetSolutionConfiguration(solutionFile, solutionConfiguration);

solutionConfigurationProperties.AddProperty("CurrentSolutionConfigurationContents", escapedSolutionConfigurationContents);

msbuildProject.AddItem(
"SolutionConfiguration",
solutionConfiguration.FullName,
new Dictionary<string, string>
{
{ "Configuration", solutionConfiguration.ConfigurationName },
{ "Platform", solutionConfiguration.PlatformName },
{ "Content", escapedSolutionConfigurationContents },
});
}

internal static string GetSolutionConfiguration(SolutionFile solutionFile, SolutionConfigurationInSolution solutionConfiguration)
{
var solutionConfigurationContents = new StringBuilder(1024);
var settings = new XmlWriterSettings
{
Expand Down Expand Up @@ -292,19 +309,8 @@ internal static void AddPropertyGroupForSolutionConfiguration(ProjectRootElement
xw.WriteEndElement(); // </SolutionConfiguration>
}

var escapedSolutionConfigurationContents = EscapingUtilities.Escape(solutionConfigurationContents.ToString());

solutionConfigurationProperties.AddProperty("CurrentSolutionConfigurationContents", escapedSolutionConfigurationContents);

msbuildProject.AddItem(
"SolutionConfiguration",
solutionConfiguration.FullName,
new Dictionary<string, string>
{
{ "Configuration", solutionConfiguration.ConfigurationName },
{ "Platform", solutionConfiguration.PlatformName },
{ "Content", escapedSolutionConfigurationContents },
});
string escapedSolutionConfigurationContents = EscapingUtilities.Escape(solutionConfigurationContents.ToString());
return escapedSolutionConfigurationContents;
}

/// <summary>
Expand Down
Loading