Skip to content
Open
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
1 change: 1 addition & 0 deletions build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ if %errorlevel%==0 (
set skipFlags="/p:SkipUsingCrossgen=true /p:SkipBuildingInstallers=true"
)
set DOTNET_SYSTEM_NET_SECURITY_NOREVOCATIONCHECKBYDEFAULT=true
set DOTNET_CLI_USE_MSBUILD_SERVER=1
powershell -NoLogo -NoProfile -ExecutionPolicy ByPass -command "& """%~dp0eng\common\build.ps1""" -restore -build -msbuildEngine dotnet %skipFlags% /tlp:summary %*"
exit /b %ErrorLevel%
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ if [[ "$@" != *"-pack"* ]]; then
fi

export DOTNET_SYSTEM_NET_SECURITY_NOREVOCATIONCHECKBYDEFAULT="true"
export DOTNET_CLI_USE_MSBUILD_SERVER=1
. "$ScriptRoot/eng/common/build.sh" --build --restore $skipFlags /tlp:summary "$@"
3 changes: 3 additions & 0 deletions build/RunTestsOnHelix.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ set DOTNET_SDK_TEST_EXECUTION_DIRECTORY=%TestExecutionDirectory%
set DOTNET_SDK_TEST_MSBUILDSDKRESOLVER_FOLDER=%HELIX_CORRELATION_PAYLOAD%\r
set DOTNET_SDK_TEST_ASSETS_DIRECTORY=%TestExecutionDirectory%\TestAssets

set DOTNET_CLI_USE_MSBUILD_SERVER=1
set MSBUILDUSESERVER=1

REM call dotnet new so the first run message doesn't interfere with the first test
dotnet new --debug:ephemeral-hive

Expand Down
3 changes: 2 additions & 1 deletion build/RunTestsOnHelix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ cp -a $HELIX_CORRELATION_PAYLOAD/t/TestExecutionDirectoryFiles/. $TestExecutionD
export DOTNET_SDK_TEST_EXECUTION_DIRECTORY=$TestExecutionDirectory
export DOTNET_SDK_TEST_MSBUILDSDKRESOLVER_FOLDER=$HELIX_CORRELATION_PAYLOAD/r
export DOTNET_SDK_TEST_ASSETS_DIRECTORY=$TestExecutionDirectory/TestAssets

export DOTNET_CLI_USE_MSBUILD_SERVER=1
export MSBUILDUSESERVER=1
# call dotnet new so the first run message doesn't interfere with the first test
dotnet new --debug:ephemeral-hive

Expand Down
4 changes: 4 additions & 0 deletions eng/dogfood.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ try {
$env:DOTNET_ROOT = $TestDotnetRoot
$env:DOTNET_ADD_GLOBAL_TOOLS_TO_PATH="0"

# MSBuild dogfood
$env:DOTNET_CLI_USE_MSBUILD_SERVER=1
$env:MSBUILDUSESERVER=1

# Avoid downloading Microsoft.Net.Sdk.Compilers.Toolset from feed
# Locally built SDK package version is Major.Minor.0-dev, which won't be available.
$env:BuildWithNetFrameworkHostedCompiler = $false
Expand Down
4 changes: 4 additions & 0 deletions eng/dogfood.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export DOTNET_MSBUILD_SDK_RESOLVER_SDKS_DIR="$testDotnetRoot/sdk/$testDotnetVers
export MicrosoftNETBuildExtensionsTargets="$artifacts_dir/bin/$configuration/Sdks/Microsoft.NET.Build.Extensions/msbuildExtensions/Microsoft/Microsoft.NET.Build.Extensions/Microsoft.NET.Build.Extensions.targets"

export PATH=$testDotnetRoot:$PATH

export DOTNET_CLI_USE_MSBUILD_SERVER=1
export MSBUILDUSESERVER=1

export DOTNET_ROOT=$testDotnetRoot
export DOTNET_ADD_GLOBAL_TOOLS_TO_PATH=0
export PS1="(dogfood) $PS1"
Expand Down
10 changes: 10 additions & 0 deletions eng/dotnet-format/dotnet-format-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,14 @@ jobs:
- template: /eng/common/templates/steps/enable-internal-sources.yml
- script: .\restore.cmd ${{ parameters.runtimeSourceProperties }}
displayName: 🟣 Restore dependencies
env:
DOTNET_CLI_USE_MSBUILD_SERVER: 1
- script: |
.\artifacts\sdk-build-env.bat
dotnet run --project .\src\BuiltInTools\dotnet-format\dotnet-format.csproj -c Release -- @eng\dotnet-format\validate.rsp
displayName: 🟣 Run dotnet-format
env:
DOTNET_CLI_USE_MSBUILD_SERVER: 1
- task: ${{ parameters.oneESCompat.publishTaskPrefix }}PublishBuildArtifacts@1
displayName: 🟣 Publish Logs
inputs:
Expand All @@ -110,9 +114,15 @@ jobs:
- template: /eng/common/templates/steps/enable-internal-sources.yml
- script: eng\dotnet-format\integration-test.cmd -repo '${{ testArgs._repo }}' -branchName '${{ testArgs._branchName }}' -sha '${{ testArgs._sha }}' -targetSolution '${{ testArgs._targetSolution }}' -useParentSdk ${{ testArgs._useParentSdk }} -testPath '$(Agent.TempDirectory)\temp' -stage 'prepare' -runtimeSourceProperties '${{ parameters.runtimeSourceProperties }}'
displayName: 🟣 Prepare ${{ testArgs._repoName }} for formatting
env:
DOTNET_CLI_USE_MSBUILD_SERVER: 1

- script: eng\dotnet-format\integration-test.cmd -repo '${{ testArgs._repo }}' -branchName '${{ testArgs._branchName }}' -sha '${{ testArgs._sha }}' -targetSolution '${{ testArgs._targetSolution }}' -useParentSdk ${{ testArgs._useParentSdk }} -testPath '$(Agent.TempDirectory)\temp' -stage 'format-workspace'
displayName: 🟣 Run dotnet-format on ${{ testArgs._repoName }} ${{ testArgs._targetSolution }}
env:
DOTNET_CLI_USE_MSBUILD_SERVER: 1

- script: eng\dotnet-format\integration-test.cmd -repo '${{ testArgs._repo }}' -branchName '${{ testArgs._branchName }}' -sha '${{ testArgs._sha }}' -targetSolution '${{ testArgs._targetSolution }}' -useParentSdk ${{ testArgs._useParentSdk }} -testPath '$(Agent.TempDirectory)\temp' -stage 'format-folder'
displayName: 🟣 Run dotnet-format on ${{ testArgs._repoName }} repo folder
env:
DOTNET_CLI_USE_MSBUILD_SERVER: 1
2 changes: 2 additions & 0 deletions eng/pipelines/templates/jobs/sdk-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ jobs:
env:
BuildConfig: $(buildConfiguration)
TestFullMSBuild: ${{ parameters.testFullMSBuild }}
DOTNET_CLI_USE_MSBUILD_SERVER: 1

- powershell: build/RunTestTemplateTests.ps1
displayName: 🟣 Run Test Templates Tests
Expand Down Expand Up @@ -131,6 +132,7 @@ jobs:
displayName: 🟣 Build
env:
BuildConfig: $(buildConfiguration)
DOTNET_CLI_USE_MSBUILD_SERVER: 1
OPENSSL_ENABLE_SHA1_SIGNATURES: 1

############### TESTING ###############
Expand Down
3 changes: 3 additions & 0 deletions eng/pipelines/templates/variables/sdk-defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ variables:
linuxOsglibcProperties: /p:OSName=linux
helixTargetContainerPrefix: '@mcr.microsoft.com/dotnet-buildtools/prereqs:'

# Use MSBuild server globally
DOTNET_CLI_USE_MSBUILD_SERVER: 1

############### ARCADE ###############
# "Post-build signing" means that this build will NOT sign itself.
PostBuildSign: true
Expand Down
2 changes: 2 additions & 0 deletions eng/restore-toolset.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ function CreateBuildEnvScripts()
$scriptContents = @"
@echo off
title SDK Build ($RepoRoot)
set DOTNET_CLI_USE_MSBUILD_SERVER=1
set MSBUILDUSESERVER=1
Copy link
Member

@jjonescz jjonescz Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be added to the sdk-build-env.ps1 too which is constructed below.

That might explain why only linux legs are currently failing and windows ones are not.

Copy link
Member

@jjonescz jjonescz Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I'm dogfooding this while investigating the failures that happen in CI. I cannot repro them so far but I noticed something:

When I run

dotnet test ./test/dotnet.Tests/ --filter "FullyQualifiedName~RunFileTests.Pack"

I normally see all the test results in the stdout.

But when I set DOTNET_CLI_USE_MSBUILD_SERVER=1 before running that same command, it seems a separate process is used to run the tests. But the original dotnet test process doesn't show any test outputs. Which also impacts my ability to inspect what is going on...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed this while debugging and I agree it is annoying and problematic.
I think I will have to take a look at the way sdk launches the msbuild app for tests - server adds one layer of indirection (e.g. it spawns another process) for the build. There is supposed to be some redirect, but the tests are wired separately from the rest.

public class MSBuildCommand(
    IEnumerable<string> msbuildArgs,
    string? msbuildPath = null
) : MSBuildForwardingApp(MSBuildArgs.AnalyzeMSBuildArguments([..msbuildArgs], CommonOptions.PropertiesOption,

vs

public class MSBuildCommand : TestCommand

so maybe these are working differently?

set DOTNET_MULTILEVEL_LOOKUP=0
REM https://aka.ms/vs/unsigned-dotnet-debugger-lib
set VSDebugger_ValidateDotnetDebugLibSignatures=0
Expand Down
3 changes: 2 additions & 1 deletion eng/restore-toolset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ function CreateBuildEnvScript {
scriptContents="
#!/usr/bin/env bash
export DOTNET_MULTILEVEL_LOOKUP=0

export DOTNET_CLI_USE_MSBUILD_SERVER=1
export MSBUILDUSESERVER=1
export DOTNET_ROOT=$DOTNET_INSTALL_DIR
export DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR=$DOTNET_INSTALL_DIR

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class GivenThatWeWantToPublishIncrementally : SdkTest
{
public GivenThatWeWantToPublishIncrementally(ITestOutputHelper log) : base(log)
{
// During the dogfood, we want the MSBuild server on for build of the pipeline. Not for the tests - it breaks outputs.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though I cannot repro the failures locally, could the problem with RunFileTests.Pack be that it relies on dotnet/msbuild#12156, i.e., the virtual in-memory project should be available for MSBuild sub-tasks, and that is not working with MSBuild server?

Environment.SetEnvironmentVariable("DOTNET_CLI_USE_MSBUILD_SERVER", "0");
}

[Fact]
Expand Down Expand Up @@ -151,7 +153,6 @@ public void It_cleans_before_trimmed_single_file_publish()

// Publish trimmed
var publishCommand = new PublishCommand(testAsset);

publishCommand
.Execute()
.Should()
Expand Down
12 changes: 6 additions & 6 deletions test/dotnet-watch.Tests/Build/EvaluationTests.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Text.RegularExpressions;
using Microsoft.VisualStudio.TestPlatform.Utilities;

namespace Microsoft.DotNet.Watch.UnitTests
{
public class EvaluationTests(ITestOutputHelper output)
{
private readonly TestLogger _logger = new(output);
private readonly TestAssetsManager _testAssets = new(output);
private readonly TestLogger _logger = new TestLogger(output);
private readonly TestAssetsManager _testAssets = new TestAssetsManager(output);

private static string MuxerPath
=> TestContext.Current.ToolsetUnderTest.DotNetHostPath;
Expand Down Expand Up @@ -430,11 +432,10 @@ public async Task ProjectReferences_Graph()
var processRunner = new ProcessRunner(processCleanupTimeout: TimeSpan.Zero);
var buildReporter = new BuildReporter(_logger, new GlobalOptions(), options);

var filesetFactory = new MSBuildFileSetFactory(projectA, buildArguments: ["/p:_DotNetWatchTraceOutput=true"], processRunner, buildReporter);
var filesetFactory = new MSBuildFileSetFactory(projectA, buildArguments: ["/p:_DotNetWatchTraceOutput=true", "/tl:Off"], processRunner, buildReporter);

var result = await filesetFactory.TryCreateAsync(requireProjectGraph: null, CancellationToken.None);
Assert.NotNull(result);

AssertEx.SequenceEqual(
[
"A/A.cs: [A/A.csproj]",
Expand Down Expand Up @@ -490,10 +491,9 @@ public async Task MsbuildOutput()
var processRunner = new ProcessRunner(processCleanupTimeout: TimeSpan.Zero);
var buildReporter = new BuildReporter(_logger, new GlobalOptions(), options);

var factory = new MSBuildFileSetFactory(project1Path, buildArguments: [], processRunner, buildReporter);
var factory = new MSBuildFileSetFactory(project1Path, buildArguments: ["/tl:Off"], processRunner, buildReporter);
var result = await factory.TryCreateAsync(requireProjectGraph: null, CancellationToken.None);
Assert.Null(result);

// note: msbuild prints errors to stdout, we match the pattern and report as error:
AssertEx.Equal(
$"[Error] {project1Path} : error NU1201: Project Project2 is not compatible with net462 (.NETFramework,Version=v4.6.2). Project Project2 supports: netstandard2.1 (.NETStandard,Version=v2.1)",
Expand Down
Loading