From 336038d008ef36acb0d6df4d8d757718f0be2588 Mon Sep 17 00:00:00 2001
From: Doug Bunting <6431421+dougbu@users.noreply.github.com>
Date: Fri, 3 Mar 2023 19:15:45 -0800
Subject: [PATCH 1/4] Use `msbuild` from VS 2022 if available - should ease
local and TeamCity builds - make `%InstallDir%` unquoted (unlike `%vswhere%`)
- shorten `%Path%` slightly - nits: - switch to 64bit `msbuild` - use
script location more; no need to change directories
---
build.cmd | 35 +++++++++++++++++++++++++----------
eng/GetXCopyMSBuild.ps1 | 3 ++-
2 files changed, 27 insertions(+), 11 deletions(-)
diff --git a/build.cmd b/build.cmd
index 500eb973a..4c989ec14 100644
--- a/build.cmd
+++ b/build.cmd
@@ -1,5 +1,4 @@
@echo off
-pushd %~dp0
setlocal
if exist bin goto Build
@@ -29,7 +28,7 @@ for /f "usebackq tokens=*" %%i in (`%vswhere% -version 16 -latest -prerelease -p
-requires Microsoft.Net.Component.4.5.2.TargetingPack ^
-requires Microsoft.Net.Component.4.6.2.TargetingPack ^
-property installationPath`) do (
- set InstallDir="%%i"
+ set "InstallDir=%%i"
)
if not DEFINED InstallDir (
@@ -38,35 +37,53 @@ if not DEFINED InstallDir (
goto BuildFail
)
-REM Find or install MSBuild. Need v17.4 due to our .NET SDK choice.
+REM Find a 64bit MSBuild and add it to path. Require v17.4 or later due to our .NET SDK choice.
+REM Check for VS2022 first.
+set InstallDir=
+for /f "usebackq tokens=*" %%i in (`%vswhere% -version 17.4 -latest -prerelease -products * ^
+ -requires Microsoft.Component.MSBuild ^
+ -property installationPath`) do (
+ set "InstallDir=%%i"
+)
+
+if DEFINED InstallDir (
+ REM Add MSBuild to the path.
+ set "PATH=%InstallDir%\MSBuild\Current\Bin\amd64;%PATH%"
+ goto FoundMSBuild
+)
+
+REM Otherwise find or install an xcopy-able MSBuild.
+echo "Could not find a VS2022 installation with the necessary components (MSBuild). Falling back..."
+
set "MSBuildVersion=17.4.1"
set "Command=[System.Threading.Thread]::CurrentThread.CurrentCulture = ''"
set "Command=%Command%; [System.Threading.Thread]::CurrentThread.CurrentUICulture = ''"
set "Command=%Command%; try { & '%~dp0eng\GetXCopyMSBuild.ps1' %MSBuildVersion%; exit $LASTEXITCODE }"
set "Command=%Command% catch { write-host $_; exit 1 }"
-PowerShell -NoProfile -NoLogo -ExecutionPolicy Bypass -Command "%Command%"
+PowerShell -NoProfile -NoLogo -ExecutionPolicy Bypass -Command "%Command%"
if %ERRORLEVEL% neq 0 goto BuildFail
REM Add MSBuild to the path.
-set "PATH=%CD%\.msbuild\%MSBuildVersion%\tools\MSBuild\Current\Bin\;%PATH%"
+set "PATH=%~dp0.msbuild\%MSBuildVersion%\tools\MSBuild\Current\Bin\amd64;%PATH%"
+:FoundMSBuild
REM Configure NuGet operations to work w/in this repo i.e. do not pollute system packages folder.
REM Note this causes two copies of packages restored using packages.config to land in this folder e.g.
REM StyleCpy.5.0.0/ and stylecop/5.0.0/.
-set "NUGET_PACKAGES=%CD%\packages"
+set "NUGET_PACKAGES=%~dp0packages"
REM Are we running in a local dev environment (not on CI)?
if DEFINED CI (set Desktop=false) else if DEFINED TEAMCITY_VERSION (set Desktop=false) else (set Desktop=true)
if "%1" == "" goto BuildDefaults
-MSBuild Runtime.msbuild /m /nr:false /p:Platform="Any CPU" /p:Desktop=%Desktop% /v:M ^
+MSBuild "%~dp0Runtime.msbuild" /m /nr:false /p:Platform="Any CPU" /p:Desktop=%Desktop% /v:M ^
/fl /fileLoggerParameters:LogFile=bin\msbuild.log;Verbosity=Normal /consoleLoggerParameters:Summary /t:%*
if %ERRORLEVEL% neq 0 goto BuildFail
goto BuildSuccess
:BuildDefaults
-MSBuild Runtime.msbuild /m /nr:false /p:Platform="Any CPU" /p:Desktop=%Desktop% /v:M ^
+MSBuild "%~dp0Runtime.msbuild" /m /nr:false /p:Platform="Any CPU" /p:Desktop=%Desktop% /v:M ^
/fl /fileLoggerParameters:LogFile=bin\msbuild.log;Verbosity=Normal /consoleLoggerParameters:Summary
if %ERRORLEVEL% neq 0 goto BuildFail
goto BuildSuccess
@@ -74,13 +91,11 @@ goto BuildSuccess
:BuildFail
echo.
echo *** BUILD FAILED ***
-popd
endlocal
exit /B 999
:BuildSuccess
echo.
echo **** BUILD SUCCESSFUL ***
-popd
endlocal
exit /B 0
diff --git a/eng/GetXCopyMSBuild.ps1 b/eng/GetXCopyMSBuild.ps1
index 6ab853c30..667839289 100644
--- a/eng/GetXCopyMSBuild.ps1
+++ b/eng/GetXCopyMSBuild.ps1
@@ -39,4 +39,5 @@ function InitializeXCopyMSBuild([string]$packageVersion, [bool]$install, [string
return Join-Path $packageDir 'tools'
}
-InitializeXCopyMSBuild -packageVersion $Version -install $true -ToolsDir (join-path $PWD .msbuild)
+$RepoRoot = Resolve-Path (Join-Path $PSScriptRoot '..\')
+InitializeXCopyMSBuild -packageVersion $Version -install $true -ToolsDir (join-path $RepoRoot .msbuild)
From 8e12737ae9f9eb069a8227454c808633ef73e01c Mon Sep 17 00:00:00 2001
From: Doug Bunting <6431421+dougbu@users.noreply.github.com>
Date: Mon, 6 Mar 2023 17:50:31 -0800
Subject: [PATCH 2/4] React to new build issues - follow up to #396 (unsure
why new FxCop and "spelling" errors didn't fail that PR)
---
src/System.Net.Http.Formatting/GlobalSuppressions.cs | 2 ++
src/System.Net.Http.Formatting/Properties/Resources.resx | 4 ++--
.../Formatting/DataContractJsonMediaTypeFormatterTests.cs | 4 ++--
.../Formatting/XmlMediaTypeFormatterTests.cs | 4 ++--
4 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/src/System.Net.Http.Formatting/GlobalSuppressions.cs b/src/System.Net.Http.Formatting/GlobalSuppressions.cs
index deefc5652..d815e56e6 100644
--- a/src/System.Net.Http.Formatting/GlobalSuppressions.cs
+++ b/src/System.Net.Http.Formatting/GlobalSuppressions.cs
@@ -6,3 +6,5 @@
[assembly: SuppressMessage("Microsoft.Design", "CA2210:AssembliesShouldHaveValidStrongNames")]
[assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "System.Net.Http.Headers", Justification = "We follow the layout of System.Net.Http.")]
[assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "System.Net.Http.Handlers", Justification = "Handlers provide an extensibility hook which we want to keep in a separate namespace.")]
+// Some resources are specific to the netstandard1.3 assembly
+[assembly: SuppressMessage("Microsoft.Web.FxCop", "MW1000:UnusedResourceUsageRule", Justification = "There are a few unused resources due to missing netstandard1.3 features.")]
diff --git a/src/System.Net.Http.Formatting/Properties/Resources.resx b/src/System.Net.Http.Formatting/Properties/Resources.resx
index ef5c4a7db..82d90e68c 100644
--- a/src/System.Net.Http.Formatting/Properties/Resources.resx
+++ b/src/System.Net.Http.Formatting/Properties/Resources.resx
@@ -358,9 +358,9 @@
Cannot access a closed stream.
- Unable to validate types on this platform when {0} is 'true'. Please reset {0} or move to a supported platform, one where the 'netstandard2.0' assembly is usable.
+ Unable to validate types on this platform when {0} is 'true'. Please reset {0} or move to a supported platform, one where the .NET Standard 2.0 assembly is usable.
- Unable to validate types on this platform when {0} is 'false'. Please set {0} or move to a supported platform, one where the 'netstandard2.0' assembly is usable.
+ Unable to validate types on this platform when {0} is 'false'. Please set {0} or move to a supported platform, one where the .NET Standard 2.0 assembly is usable.
\ No newline at end of file
diff --git a/test/System.Net.Http.Formatting.Test/Formatting/DataContractJsonMediaTypeFormatterTests.cs b/test/System.Net.Http.Formatting.Test/Formatting/DataContractJsonMediaTypeFormatterTests.cs
index 7ad93ee2a..b94b19598 100644
--- a/test/System.Net.Http.Formatting.Test/Formatting/DataContractJsonMediaTypeFormatterTests.cs
+++ b/test/System.Net.Http.Formatting.Test/Formatting/DataContractJsonMediaTypeFormatterTests.cs
@@ -193,7 +193,7 @@ await Assert.ThrowsAsync(() =>
formatter.ReadFromStreamAsync(variationType, stream, content, formatterLogger: null),
"Unable to validate types on this platform when UseDataContractJsonSerializer is 'true'. " +
"Please reset UseDataContractJsonSerializer or move to a supported platform, one where the " +
- "'netstandard2.0' assembly is usable.");
+ ".NET Standard 2.0 assembly is usable.");
}
}
@@ -211,7 +211,7 @@ await Assert.ThrowsAsync(() =>
formatter.WriteToStreamAsync(variationType, testData, stream, content, transportContext: null),
"Unable to validate types on this platform when UseDataContractJsonSerializer is 'true'. " +
"Please reset UseDataContractJsonSerializer or move to a supported platform, one where the " +
- "'netstandard2.0' assembly is usable.");
+ ".NET Standard 2.0 assembly is usable.");
}
#else
diff --git a/test/System.Net.Http.Formatting.Test/Formatting/XmlMediaTypeFormatterTests.cs b/test/System.Net.Http.Formatting.Test/Formatting/XmlMediaTypeFormatterTests.cs
index c83f687ec..8dd69fe12 100644
--- a/test/System.Net.Http.Formatting.Test/Formatting/XmlMediaTypeFormatterTests.cs
+++ b/test/System.Net.Http.Formatting.Test/Formatting/XmlMediaTypeFormatterTests.cs
@@ -516,7 +516,7 @@ public async Task ReadFromStreamAsync_UsingDataContractSerializer_Throws(Type va
await Assert.ThrowsAsync(() =>
formatter.ReadFromStreamAsync(variationType, stream, content, formatterLogger: null),
"Unable to validate types on this platform when UseXmlSerializer is 'false'. Please set " +
- "UseXmlSerializer or move to a supported platform, one where the 'netstandard2.0' assembly " +
+ "UseXmlSerializer or move to a supported platform, one where the .NET Standard 2.0 assembly " +
"is usable.");
}
}
@@ -534,7 +534,7 @@ public async Task WriteToStreamAsync_UsingDataContractSerializer_Throws(Type var
await Assert.ThrowsAsync(() =>
formatter.WriteToStreamAsync(variationType, testData, stream, content, transportContext: null),
"Unable to validate types on this platform when UseXmlSerializer is 'false'. Please set " +
- "UseXmlSerializer or move to a supported platform, one where the 'netstandard2.0' assembly " +
+ "UseXmlSerializer or move to a supported platform, one where the .NET Standard 2.0 assembly " +
"is usable.");
}
From 7ca7468118fe1d02f4cd696bd002c13395134476 Mon Sep 17 00:00:00 2001
From: Doug Bunting <6431421+dougbu@users.noreply.github.com>
Date: Mon, 6 Mar 2023 21:05:55 -0800
Subject: [PATCH 3/4] Put `PortReserver` users into an xUnit collection
---
test/Microsoft.TestCommon/PortReserver.cs | 5 +++++
test/System.Web.Http.Owin.Test/OwinHostIntegrationTest.cs | 1 +
.../Authentication/BasicOverHttpTest.cs | 1 +
.../HttpSelfHostResponseTest.cs | 1 +
test/System.Web.Http.SelfHost.Test/HttpSelfHostServerTest.cs | 1 +
5 files changed, 9 insertions(+)
diff --git a/test/Microsoft.TestCommon/PortReserver.cs b/test/Microsoft.TestCommon/PortReserver.cs
index f085399af..bfa95d610 100644
--- a/test/Microsoft.TestCommon/PortReserver.cs
+++ b/test/Microsoft.TestCommon/PortReserver.cs
@@ -12,6 +12,11 @@
namespace Microsoft.TestCommon
{
+ [Xunit.CollectionDefinition("PortReserver Collection", DisableParallelization = true)]
+ public class PortReserverCollection
+ {
+ }
+
///
/// This class allocates ports while ensuring that:
/// 1. Ports that are permanently taken (or taken for the duration of the test) are not being attempted to be used.
diff --git a/test/System.Web.Http.Owin.Test/OwinHostIntegrationTest.cs b/test/System.Web.Http.Owin.Test/OwinHostIntegrationTest.cs
index 17e2d15d0..1300d1fd5 100644
--- a/test/System.Web.Http.Owin.Test/OwinHostIntegrationTest.cs
+++ b/test/System.Web.Http.Owin.Test/OwinHostIntegrationTest.cs
@@ -12,6 +12,7 @@
namespace System.Web.Http.Owin
{
+ [Xunit.Collection("PortReserver Collection")] // Avoid conflicts between different PortReserver consumers.
public class OwinHostIntegrationTest
{
[Fact]
diff --git a/test/System.Web.Http.SelfHost.Test/Authentication/BasicOverHttpTest.cs b/test/System.Web.Http.SelfHost.Test/Authentication/BasicOverHttpTest.cs
index 0b2a5739e..85cde9467 100644
--- a/test/System.Web.Http.SelfHost.Test/Authentication/BasicOverHttpTest.cs
+++ b/test/System.Web.Http.SelfHost.Test/Authentication/BasicOverHttpTest.cs
@@ -10,6 +10,7 @@
namespace System.Web.Http
{
+ [Xunit.Collection("PortReserver Collection")] // Avoid conflicts between different PortReserver consumers.
public class BasicOverHttpTest
{
[Fact]
diff --git a/test/System.Web.Http.SelfHost.Test/HttpSelfHostResponseTest.cs b/test/System.Web.Http.SelfHost.Test/HttpSelfHostResponseTest.cs
index bb192b922..8a8919057 100644
--- a/test/System.Web.Http.SelfHost.Test/HttpSelfHostResponseTest.cs
+++ b/test/System.Web.Http.SelfHost.Test/HttpSelfHostResponseTest.cs
@@ -12,6 +12,7 @@
namespace System.Web.Http.SelfHost
{
+ [Xunit.Collection("PortReserver Collection")] // Avoid conflicts between different PortReserver consumers.
public class HttpSelfHostResponseTest
{
[Fact]
diff --git a/test/System.Web.Http.SelfHost.Test/HttpSelfHostServerTest.cs b/test/System.Web.Http.SelfHost.Test/HttpSelfHostServerTest.cs
index afd3b77c2..a53f4ba3c 100644
--- a/test/System.Web.Http.SelfHost.Test/HttpSelfHostServerTest.cs
+++ b/test/System.Web.Http.SelfHost.Test/HttpSelfHostServerTest.cs
@@ -18,6 +18,7 @@
namespace System.Web.Http.SelfHost
{
+ [Xunit.Collection("PortReserver Collection")] // Avoid conflicts between different PortReserver consumers.
public class HttpSelfHostServerTest : IDisposable
{
private HttpSelfHostServer server = null;
From 63890faddd934e5e1eee3189f1ac5142e7f568dd Mon Sep 17 00:00:00 2001
From: Doug Bunting <6431421+dougbu@users.noreply.github.com>
Date: Mon, 6 Mar 2023 21:45:26 -0800
Subject: [PATCH 4/4] Go back to x86 `msbuild` - seems to resolve `Moq`
assembly load issue
---
build.cmd | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/build.cmd b/build.cmd
index 4c989ec14..6b591d1da 100644
--- a/build.cmd
+++ b/build.cmd
@@ -48,7 +48,7 @@ for /f "usebackq tokens=*" %%i in (`%vswhere% -version 17.4 -latest -prerelease
if DEFINED InstallDir (
REM Add MSBuild to the path.
- set "PATH=%InstallDir%\MSBuild\Current\Bin\amd64;%PATH%"
+ set "PATH=%InstallDir%\MSBuild\Current\Bin;%PATH%"
goto FoundMSBuild
)
@@ -64,7 +64,7 @@ PowerShell -NoProfile -NoLogo -ExecutionPolicy Bypass -Command "%Command%"
if %ERRORLEVEL% neq 0 goto BuildFail
REM Add MSBuild to the path.
-set "PATH=%~dp0.msbuild\%MSBuildVersion%\tools\MSBuild\Current\Bin\amd64;%PATH%"
+set "PATH=%~dp0.msbuild\%MSBuildVersion%\tools\MSBuild\Current\Bin;%PATH%"
:FoundMSBuild
REM Configure NuGet operations to work w/in this repo i.e. do not pollute system packages folder.