Use `msbuild` from VS 2022 if available (#395)

* Use `msbuild` from VS 2022 if available
  - should ease local and TeamCity builds
  - make `%InstallDir%` unquoted (unlike `%vswhere%`)
    - shorten `%Path%` slightly
  - nits:
    - use script location more; no need to change directories

* React to new build issues
  - follow up to #396
    (unsure why new FxCop and "spelling" errors didn't fail that PR)

* Put `PortReserver` users into an xUnit collection
This commit is contained in:
Doug Bunting 2023-03-06 22:07:37 -08:00 коммит произвёл GitHub
Родитель 6451d777f7
Коммит 2da072a141
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
11 изменённых файлов: 44 добавлений и 17 удалений

Просмотреть файл

@ -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;%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;%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

Просмотреть файл

@ -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)

Просмотреть файл

@ -6,3 +6,5 @@ using System.Diagnostics.CodeAnalysis;
[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.")]

Просмотреть файл

@ -358,9 +358,9 @@
<value>Cannot access a closed stream.</value>
</data>
<data name="JsonMediaTypeFormatter_DCS_NotSupported" xml:space="preserve">
<value>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.</value>
<value>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.</value>
</data>
<data name="XmlMediaTypeFormatter_DCS_NotSupported" xml:space="preserve">
<value>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.</value>
<value>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.</value>
</data>
</root>

Просмотреть файл

@ -12,6 +12,11 @@ using System.Threading;
namespace Microsoft.TestCommon
{
[Xunit.CollectionDefinition("PortReserver Collection", DisableParallelization = true)]
public class PortReserverCollection
{
}
/// <summary>
/// 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.

Просмотреть файл

@ -193,7 +193,7 @@ namespace System.Net.Http.Formatting
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 @@ namespace System.Net.Http.Formatting
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

Просмотреть файл

@ -516,7 +516,7 @@ namespace System.Net.Http.Formatting
await Assert.ThrowsAsync<PlatformNotSupportedException>(() =>
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 @@ namespace System.Net.Http.Formatting
await Assert.ThrowsAsync<PlatformNotSupportedException>(() =>
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.");
}

Просмотреть файл

@ -12,6 +12,7 @@ using Owin;
namespace System.Web.Http.Owin
{
[Xunit.Collection("PortReserver Collection")] // Avoid conflicts between different PortReserver consumers.
public class OwinHostIntegrationTest
{
[Fact]

Просмотреть файл

@ -10,6 +10,7 @@ using Microsoft.TestCommon;
namespace System.Web.Http
{
[Xunit.Collection("PortReserver Collection")] // Avoid conflicts between different PortReserver consumers.
public class BasicOverHttpTest
{
[Fact]

Просмотреть файл

@ -12,6 +12,7 @@ using Microsoft.TestCommon;
namespace System.Web.Http.SelfHost
{
[Xunit.Collection("PortReserver Collection")] // Avoid conflicts between different PortReserver consumers.
public class HttpSelfHostResponseTest
{
[Fact]

Просмотреть файл

@ -18,6 +18,7 @@ using Microsoft.TestCommon;
namespace System.Web.Http.SelfHost
{
[Xunit.Collection("PortReserver Collection")] // Avoid conflicts between different PortReserver consumers.
public class HttpSelfHostServerTest : IDisposable
{
private HttpSelfHostServer server = null;