Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into imports-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cartermp authored Dec 9, 2020
2 parents a37a240 + 822fc20 commit 2e114db
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 62 deletions.
8 changes: 4 additions & 4 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<ProductDependencies>
</ProductDependencies>
<ToolsetDependencies>
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="6.0.0-beta.20601.2">
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="6.0.0-beta.20607.11">
<Uri>https://github.com/dotnet/arcade</Uri>
<Sha>6d8efa00a7dd2d15e07df673a83cecb8a0a3031f</Sha>
<Sha>ae4226e0521b46075925444f3d733e05ae74dc0d</Sha>
</Dependency>
<Dependency Name="Microsoft.DotNet.Helix.Sdk" Version="6.0.0-beta.20601.2">
<Dependency Name="Microsoft.DotNet.Helix.Sdk" Version="6.0.0-beta.20607.11">
<Uri>https://github.com/dotnet/arcade</Uri>
<Sha>6d8efa00a7dd2d15e07df673a83cecb8a0a3031f</Sha>
<Sha>ae4226e0521b46075925444f3d733e05ae74dc0d</Sha>
</Dependency>
</ToolsetDependencies>
</Dependencies>
2 changes: 1 addition & 1 deletion eng/common/performance/microbenchmarks.proj
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,4 @@
<Timeout>4:00</Timeout>
</HelixWorkItem>
</ItemGroup>
</Project>
</Project>
104 changes: 61 additions & 43 deletions eng/common/pipeline-logging-functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ function Write-PipelineTelemetryError {
[switch]$AsOutput,
[switch]$Force)

$PSBoundParameters.Remove('Category') | Out-Null
$PSBoundParameters.Remove('Category') | Out-Null

if($Force -Or ((Test-Path variable:ci) -And $ci)) {
$Message = "(NETCORE_ENGINEERING_TELEMETRY=$Category) $Message"
}
$PSBoundParameters.Remove('Message') | Out-Null
$PSBoundParameters.Add('Message', $Message)
Write-PipelineTaskError @PSBoundParameters
if ($Force -Or ((Test-Path variable:ci) -And $ci)) {
$Message = "(NETCORE_ENGINEERING_TELEMETRY=$Category) $Message"
}
$PSBoundParameters.Remove('Message') | Out-Null
$PSBoundParameters.Add('Message', $Message)
Write-PipelineTaskError @PSBoundParameters
}

# Specify "-Force" to force pipeline formatted output even if "$ci" is false or not set
Expand All @@ -55,8 +55,8 @@ function Write-PipelineTaskError {
[switch]$Force
)

if(!$Force -And (-Not (Test-Path variable:ci) -Or !$ci)) {
if($Type -eq 'error') {
if (!$Force -And (-Not (Test-Path variable:ci) -Or !$ci)) {
if ($Type -eq 'error') {
Write-Host $Message -ForegroundColor Red
return
}
Expand All @@ -66,47 +66,61 @@ function Write-PipelineTaskError {
}
}

if(($Type -ne 'error') -and ($Type -ne 'warning')) {
if (($Type -ne 'error') -and ($Type -ne 'warning')) {
Write-Host $Message
return
}
$PSBoundParameters.Remove('Force') | Out-Null
if(-not $PSBoundParameters.ContainsKey('Type')) {
if (-not $PSBoundParameters.ContainsKey('Type')) {
$PSBoundParameters.Add('Type', 'error')
}
Write-LogIssue @PSBoundParameters
}
}

function Write-PipelineSetVariable {
function Write-PipelineSetVariable {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$Name,
[string]$Value,
[switch]$Secret,
[switch]$AsOutput,
[bool]$IsMultiJobVariable=$true)

if((Test-Path variable:ci) -And $ci) {
[Parameter(Mandatory = $true)]
[string]$Name,
[string]$Value,
[switch]$Secret,
[switch]$AsOutput,
[bool]$IsMultiJobVariable = $true)

if ((Test-Path variable:ci) -And $ci) {
Write-LoggingCommand -Area 'task' -Event 'setvariable' -Data $Value -Properties @{
'variable' = $Name
'isSecret' = $Secret
'isOutput' = $IsMultiJobVariable
'variable' = $Name
'isSecret' = $Secret
'isOutput' = $IsMultiJobVariable
} -AsOutput:$AsOutput
}
}
}
}

function Write-PipelinePrependPath {
function Write-PipelinePrependPath {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string]$Path,
[switch]$AsOutput)
[Parameter(Mandatory = $true)]
[string]$Path,
[switch]$AsOutput)

if((Test-Path variable:ci) -And $ci) {
if ((Test-Path variable:ci) -And $ci) {
Write-LoggingCommand -Area 'task' -Event 'prependpath' -Data $Path -AsOutput:$AsOutput
}
}
}
}

function Write-PipelineSetResult {
[CmdletBinding()]
param(
[ValidateSet("Succeeded", "SucceededWithIssues", "Failed", "Cancelled", "Skipped")]
[Parameter(Mandatory = $true)]
[string]$Result,
[string]$Message)
if ((Test-Path variable:ci) -And $ci) {
Write-LoggingCommand -Area 'task' -Event 'complete' -Data $Message -Properties @{
'result' = $Result
}
}
}

<########################################
# Private functions.
Expand All @@ -123,7 +137,8 @@ function Format-LoggingCommandData {
foreach ($mapping in $script:loggingCommandEscapeMappings) {
$Value = $Value.Replace($mapping.Token, $mapping.Replacement)
}
} else {
}
else {
for ($i = $script:loggingCommandEscapeMappings.Length - 1 ; $i -ge 0 ; $i--) {
$mapping = $script:loggingCommandEscapeMappings[$i]
$Value = $Value.Replace($mapping.Replacement, $mapping.Token)
Expand Down Expand Up @@ -156,7 +171,8 @@ function Format-LoggingCommand {
if ($first) {
$null = $sb.Append(' ')
$first = $false
} else {
}
else {
$null = $sb.Append(';')
}

Expand Down Expand Up @@ -193,7 +209,8 @@ function Write-LoggingCommand {
$command = Format-LoggingCommand -Area $Area -Event $Event -Data $Data -Properties $Properties
if ($AsOutput) {
$command
} else {
}
else {
Write-Host $command
}
}
Expand All @@ -212,12 +229,12 @@ function Write-LogIssue {
[switch]$AsOutput)

$command = Format-LoggingCommand -Area 'task' -Event 'logissue' -Data $Message -Properties @{
'type' = $Type
'code' = $ErrCode
'sourcepath' = $SourcePath
'linenumber' = $LineNumber
'columnnumber' = $ColumnNumber
}
'type' = $Type
'code' = $ErrCode
'sourcepath' = $SourcePath
'linenumber' = $LineNumber
'columnnumber' = $ColumnNumber
}
if ($AsOutput) {
return $command
}
Expand All @@ -229,7 +246,8 @@ function Write-LogIssue {
$foregroundColor = [System.ConsoleColor]::Red
$backgroundColor = [System.ConsoleColor]::Black
}
} else {
}
else {
$foregroundColor = $host.PrivateData.WarningForegroundColor
$backgroundColor = $host.PrivateData.WarningBackgroundColor
if ($foregroundColor -isnot [System.ConsoleColor] -or $backgroundColor -isnot [System.ConsoleColor]) {
Expand Down
26 changes: 25 additions & 1 deletion eng/common/pipeline-logging-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,28 @@ function Write-PipelinePrependPath {
if [[ "$ci" == true ]]; then
echo "##vso[task.prependpath]$prepend_path"
fi
}
}

function Write-PipelineSetResult {
local result=''
local message=''

while [[ $# -gt 0 ]]; do
opt="$(echo "${1/#--/-}" | awk '{print tolower($0)}')"
case "$opt" in
-result|-r)
result=$2
shift
;;
-message|-m)
message=$2
shift
;;
esac
shift
done

if [[ "$ci" == true ]]; then
echo "##vso[task.complete result=$result;]$message"
fi
}
15 changes: 12 additions & 3 deletions eng/common/tools.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -677,14 +677,23 @@ function MSBuild-Core() {
$exitCode = Exec-Process $buildTool.Path $cmdArgs

if ($exitCode -ne 0) {
Write-PipelineTelemetryError -Category 'Build' -Message 'Build failed.'
# We should not Write-PipelineTaskError here because that message shows up in the build summary
# The build already logged an error, that's the reason it failed. Producing an error here only adds noise.
Write-Host "Build failed with exit code $exitCode. Check errors above." -ForegroundColor Red

$buildLog = GetMSBuildBinaryLogCommandLineArgument $args
if ($buildLog -ne $null) {
if ($null -ne $buildLog) {
Write-Host "See log: $buildLog" -ForegroundColor DarkGray
}

ExitWithExitCode $exitCode
if ($ci) {
Write-PipelineSetResult -Result "Failed" -Message "msbuild execution failed."
# Exiting with an exit code causes the azure pipelines task to log yet another "noise" error
# The above Write-PipelineSetResult will cause the task to be marked as failure without adding yet another error
ExitWithExitCode 0
} else {
ExitWithExitCode $exitCode
}
}
}

Expand Down
13 changes: 11 additions & 2 deletions eng/common/tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,17 @@ function MSBuild-Core {

"$_InitializeBuildTool" "$@" || {
local exit_code=$?
Write-PipelineTaskError "Build failed (exit code '$exit_code')."
ExitWithExitCode $exit_code
# We should not Write-PipelineTaskError here because that message shows up in the build summary
# The build already logged an error, that's the reason it failed. Producing an error here only adds noise.
echo "Build failed with exit code $exit_code. Check errors above."
if [[ "$ci" == "true" ]]; then
Write-PipelineSetResult -result "Failed" -message "msbuild execution failed."
# Exiting with an exit code causes the azure pipelines task to log yet another "noise" error
# The above Write-PipelineSetResult will cause the task to be marked as failure without adding yet another error
ExitWithExitCode 0
else
ExitWithExitCode $exit_code
fi
}
}

Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"rollForward": "major"
},
"msbuild-sdks": {
"Microsoft.DotNet.Arcade.Sdk": "6.0.0-beta.20601.2",
"Microsoft.DotNet.Helix.Sdk": "6.0.0-beta.20601.2"
"Microsoft.DotNet.Arcade.Sdk": "6.0.0-beta.20607.11",
"Microsoft.DotNet.Helix.Sdk": "6.0.0-beta.20607.11"
}
}
7 changes: 5 additions & 2 deletions src/MSBuild.Conversion.Project/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ public class Converter
private readonly UnconfiguredProject _project;
private readonly BaselineProject _sdkBaselineProject;
private readonly IProjectRootElement _projectRootElement;
private readonly bool _noBackup;
private readonly ImmutableDictionary<string, Differ> _differs;

public Converter(UnconfiguredProject project, BaselineProject sdkBaselineProject, IProjectRootElement projectRootElement)
public Converter(UnconfiguredProject project, BaselineProject sdkBaselineProject,
IProjectRootElement projectRootElement, bool noBackup)
{
_project = project ?? throw new ArgumentNullException(nameof(project));
_sdkBaselineProject = sdkBaselineProject;
_projectRootElement = projectRootElement ?? throw new ArgumentNullException(nameof(projectRootElement));
_noBackup = noBackup;
_differs = GetDiffers();
}

Expand All @@ -33,7 +36,7 @@ public void Convert(string outputPath)
{
return _projectRootElement
// Let's convert packages first, since that's what you should do manually anyways
.ConvertAndAddPackages(_sdkBaselineProject.ProjectStyle, _sdkBaselineProject.TargetTFM)
.ConvertAndAddPackages(_sdkBaselineProject.ProjectStyle, _sdkBaselineProject.TargetTFM, removePackagesConfig: _noBackup)

// Now we can convert the project over
.ChangeImportsAndAddSdkAttribute(_sdkBaselineProject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ private static IProjectRootElement AddPackage(this IProjectRootElement projectRo
return projectRootElement;
}

public static IProjectRootElement ConvertAndAddPackages(this IProjectRootElement projectRootElement, ProjectStyle projectStyle, string tfm)
public static IProjectRootElement ConvertAndAddPackages(this IProjectRootElement projectRootElement,
ProjectStyle projectStyle, string tfm, bool removePackagesConfig)
{
var packagesConfigItemGroup = MSBuildHelpers.GetPackagesConfigItemGroup(projectRootElement);
if (packagesConfigItemGroup is null)
Expand Down Expand Up @@ -372,6 +373,11 @@ public static IProjectRootElement ConvertAndAddPackages(this IProjectRootElement
}

packagesConfigItemGroup.RemoveChild(packagesConfigItem);
if (removePackagesConfig)
{
File.Delete(path);
}

return projectRootElement;
}

Expand Down
4 changes: 2 additions & 2 deletions src/try-convert/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static async Task<int> Main(string[] args)
.AddOption(new Option(new[] { "--force-web-conversion" }, "Attempt to convert MVC and WebAPI projects even though significant manual work is necessary after migrating such projects.") { Argument = new Argument<bool>(() => false) })
.AddOption(new Option(new[] { "--preview" }, "Use preview SDKs as part of conversion") { Argument = new Argument<bool>(() => false) })
.AddOption(new Option(new[] { "--diff-only" }, "Produces a diff of the project to convert; no conversion is done") { Argument = new Argument<bool>(() => false) })
.AddOption(new Option(new[] { "--no-backup" }, "Converts projects and does not create a backup of the originals.") { Argument = new Argument<bool>(() => false) })
.AddOption(new Option(new[] { "--no-backup" }, "Converts projects, does not create a backup of the originals and removes packages.config file.") { Argument = new Argument<bool>(() => false) })
.AddOption(new Option(new[] { "--keep-current-tfms" }, "Converts project files but does not change any TFMs. If unspecified, TFMs may change.") { Argument = new Argument<bool>(() => false) })
.Build();

Expand Down Expand Up @@ -125,7 +125,7 @@ public static int Run(string? project, string? workspace, string? msbuildPath, s
}
else
{
var converter = new Converter(item.UnconfiguredProject, item.SdkBaselineProject, item.ProjectRootElement);
var converter = new Converter(item.UnconfiguredProject, item.SdkBaselineProject, item.ProjectRootElement, noBackup);
converter.Convert(item.ProjectRootElement.FullPath);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/end-to-end/Smoke.Tests/BasicConversions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private static (IProjectRootElement baselineRootElement, IProjectRootElement con
var baselineRootElement = baselineLoader.GetRootElementFromProjectFile(projectBaselinePath);

var item = conversionWorkspace.WorkspaceItems.Single();
var converter = new Converter(item.UnconfiguredProject, item.SdkBaselineProject, item.ProjectRootElement);
var converter = new Converter(item.UnconfiguredProject, item.SdkBaselineProject, item.ProjectRootElement, noBackup: false);
var convertedRootElement = converter.ConvertProjectFile();

return (baselineRootElement, convertedRootElement);
Expand Down

0 comments on commit 2e114db

Please sign in to comment.