Skip to content

Commit 2da072a

Browse files
authored
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
1 parent 6451d77 commit 2da072a

File tree

11 files changed

+44
-17
lines changed

11 files changed

+44
-17
lines changed

Diff for: build.cmd

+25-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
@echo off
2-
pushd %~dp0
32
setlocal
43

54
if exist bin goto Build
@@ -29,7 +28,7 @@ for /f "usebackq tokens=*" %%i in (`%vswhere% -version 16 -latest -prerelease -p
2928
-requires Microsoft.Net.Component.4.5.2.TargetingPack ^
3029
-requires Microsoft.Net.Component.4.6.2.TargetingPack ^
3130
-property installationPath`) do (
32-
set InstallDir="%%i"
31+
set "InstallDir=%%i"
3332
)
3433

3534
if not DEFINED InstallDir (
@@ -38,49 +37,65 @@ if not DEFINED InstallDir (
3837
goto BuildFail
3938
)
4039

41-
REM Find or install MSBuild. Need v17.4 due to our .NET SDK choice.
40+
REM Find a 64bit MSBuild and add it to path. Require v17.4 or later due to our .NET SDK choice.
41+
REM Check for VS2022 first.
42+
set InstallDir=
43+
for /f "usebackq tokens=*" %%i in (`%vswhere% -version 17.4 -latest -prerelease -products * ^
44+
-requires Microsoft.Component.MSBuild ^
45+
-property installationPath`) do (
46+
set "InstallDir=%%i"
47+
)
48+
49+
if DEFINED InstallDir (
50+
REM Add MSBuild to the path.
51+
set "PATH=%InstallDir%\MSBuild\Current\Bin;%PATH%"
52+
goto FoundMSBuild
53+
)
54+
55+
REM Otherwise find or install an xcopy-able MSBuild.
56+
echo "Could not find a VS2022 installation with the necessary components (MSBuild). Falling back..."
57+
4258
set "MSBuildVersion=17.4.1"
4359
set "Command=[System.Threading.Thread]::CurrentThread.CurrentCulture = ''"
4460
set "Command=%Command%; [System.Threading.Thread]::CurrentThread.CurrentUICulture = ''"
4561
set "Command=%Command%; try { & '%~dp0eng\GetXCopyMSBuild.ps1' %MSBuildVersion%; exit $LASTEXITCODE }"
4662
set "Command=%Command% catch { write-host $_; exit 1 }"
47-
PowerShell -NoProfile -NoLogo -ExecutionPolicy Bypass -Command "%Command%"
63+
PowerShell -NoProfile -NoLogo -ExecutionPolicy Bypass -Command "%Command%"
4864
if %ERRORLEVEL% neq 0 goto BuildFail
4965

5066
REM Add MSBuild to the path.
51-
set "PATH=%CD%\.msbuild\%MSBuildVersion%\tools\MSBuild\Current\Bin\;%PATH%"
67+
set "PATH=%~dp0.msbuild\%MSBuildVersion%\tools\MSBuild\Current\Bin;%PATH%"
5268

69+
:FoundMSBuild
5370
REM Configure NuGet operations to work w/in this repo i.e. do not pollute system packages folder.
5471
REM Note this causes two copies of packages restored using packages.config to land in this folder e.g.
5572
REM StyleCpy.5.0.0/ and stylecop/5.0.0/.
56-
set "NUGET_PACKAGES=%CD%\packages"
73+
set "NUGET_PACKAGES=%~dp0packages"
5774

5875
REM Are we running in a local dev environment (not on CI)?
5976
if DEFINED CI (set Desktop=false) else if DEFINED TEAMCITY_VERSION (set Desktop=false) else (set Desktop=true)
6077

6178
if "%1" == "" goto BuildDefaults
6279

63-
MSBuild Runtime.msbuild /m /nr:false /p:Platform="Any CPU" /p:Desktop=%Desktop% /v:M ^
80+
MSBuild "%~dp0Runtime.msbuild" /m /nr:false /p:Platform="Any CPU" /p:Desktop=%Desktop% /v:M ^
6481
/fl /fileLoggerParameters:LogFile=bin\msbuild.log;Verbosity=Normal /consoleLoggerParameters:Summary /t:%*
6582
if %ERRORLEVEL% neq 0 goto BuildFail
6683
goto BuildSuccess
6784

6885
:BuildDefaults
69-
MSBuild Runtime.msbuild /m /nr:false /p:Platform="Any CPU" /p:Desktop=%Desktop% /v:M ^
86+
MSBuild "%~dp0Runtime.msbuild" /m /nr:false /p:Platform="Any CPU" /p:Desktop=%Desktop% /v:M ^
7087
/fl /fileLoggerParameters:LogFile=bin\msbuild.log;Verbosity=Normal /consoleLoggerParameters:Summary
7188
if %ERRORLEVEL% neq 0 goto BuildFail
7289
goto BuildSuccess
7390

7491
:BuildFail
7592
echo.
7693
echo *** BUILD FAILED ***
77-
popd
7894
endlocal
7995
exit /B 999
8096

8197
:BuildSuccess
8298
echo.
8399
echo **** BUILD SUCCESSFUL ***
84-
popd
85100
endlocal
86101
exit /B 0

Diff for: eng/GetXCopyMSBuild.ps1

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ function InitializeXCopyMSBuild([string]$packageVersion, [bool]$install, [string
3939
return Join-Path $packageDir 'tools'
4040
}
4141

42-
InitializeXCopyMSBuild -packageVersion $Version -install $true -ToolsDir (join-path $PWD .msbuild)
42+
$RepoRoot = Resolve-Path (Join-Path $PSScriptRoot '..\')
43+
InitializeXCopyMSBuild -packageVersion $Version -install $true -ToolsDir (join-path $RepoRoot .msbuild)

Diff for: src/System.Net.Http.Formatting/GlobalSuppressions.cs

+2
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66
[assembly: SuppressMessage("Microsoft.Design", "CA2210:AssembliesShouldHaveValidStrongNames")]
77
[assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "System.Net.Http.Headers", Justification = "We follow the layout of System.Net.Http.")]
88
[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.")]
9+
// Some resources are specific to the netstandard1.3 assembly
10+
[assembly: SuppressMessage("Microsoft.Web.FxCop", "MW1000:UnusedResourceUsageRule", Justification = "There are a few unused resources due to missing netstandard1.3 features.")]

Diff for: src/System.Net.Http.Formatting/Properties/Resources.resx

+2-2
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,9 @@
358358
<value>Cannot access a closed stream.</value>
359359
</data>
360360
<data name="JsonMediaTypeFormatter_DCS_NotSupported" xml:space="preserve">
361-
<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>
361+
<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>
362362
</data>
363363
<data name="XmlMediaTypeFormatter_DCS_NotSupported" xml:space="preserve">
364-
<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>
364+
<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>
365365
</data>
366366
</root>

Diff for: test/Microsoft.TestCommon/PortReserver.cs

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
namespace Microsoft.TestCommon
1414
{
15+
[Xunit.CollectionDefinition("PortReserver Collection", DisableParallelization = true)]
16+
public class PortReserverCollection
17+
{
18+
}
19+
1520
/// <summary>
1621
/// This class allocates ports while ensuring that:
1722
/// 1. Ports that are permanently taken (or taken for the duration of the test) are not being attempted to be used.

Diff for: test/System.Net.Http.Formatting.Test/Formatting/DataContractJsonMediaTypeFormatterTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ await Assert.ThrowsAsync<PlatformNotSupportedException>(() =>
193193
formatter.ReadFromStreamAsync(variationType, stream, content, formatterLogger: null),
194194
"Unable to validate types on this platform when UseDataContractJsonSerializer is 'true'. " +
195195
"Please reset UseDataContractJsonSerializer or move to a supported platform, one where the " +
196-
"'netstandard2.0' assembly is usable.");
196+
".NET Standard 2.0 assembly is usable.");
197197
}
198198
}
199199

@@ -211,7 +211,7 @@ await Assert.ThrowsAsync<PlatformNotSupportedException>(() =>
211211
formatter.WriteToStreamAsync(variationType, testData, stream, content, transportContext: null),
212212
"Unable to validate types on this platform when UseDataContractJsonSerializer is 'true'. " +
213213
"Please reset UseDataContractJsonSerializer or move to a supported platform, one where the " +
214-
"'netstandard2.0' assembly is usable.");
214+
".NET Standard 2.0 assembly is usable.");
215215
}
216216

217217
#else

Diff for: test/System.Net.Http.Formatting.Test/Formatting/XmlMediaTypeFormatterTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ public async Task ReadFromStreamAsync_UsingDataContractSerializer_Throws(Type va
516516
await Assert.ThrowsAsync<PlatformNotSupportedException>(() =>
517517
formatter.ReadFromStreamAsync(variationType, stream, content, formatterLogger: null),
518518
"Unable to validate types on this platform when UseXmlSerializer is 'false'. Please set " +
519-
"UseXmlSerializer or move to a supported platform, one where the 'netstandard2.0' assembly " +
519+
"UseXmlSerializer or move to a supported platform, one where the .NET Standard 2.0 assembly " +
520520
"is usable.");
521521
}
522522
}
@@ -534,7 +534,7 @@ public async Task WriteToStreamAsync_UsingDataContractSerializer_Throws(Type var
534534
await Assert.ThrowsAsync<PlatformNotSupportedException>(() =>
535535
formatter.WriteToStreamAsync(variationType, testData, stream, content, transportContext: null),
536536
"Unable to validate types on this platform when UseXmlSerializer is 'false'. Please set " +
537-
"UseXmlSerializer or move to a supported platform, one where the 'netstandard2.0' assembly " +
537+
"UseXmlSerializer or move to a supported platform, one where the .NET Standard 2.0 assembly " +
538538
"is usable.");
539539
}
540540

Diff for: test/System.Web.Http.Owin.Test/OwinHostIntegrationTest.cs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace System.Web.Http.Owin
1414
{
15+
[Xunit.Collection("PortReserver Collection")] // Avoid conflicts between different PortReserver consumers.
1516
public class OwinHostIntegrationTest
1617
{
1718
[Fact]

Diff for: test/System.Web.Http.SelfHost.Test/Authentication/BasicOverHttpTest.cs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace System.Web.Http
1212
{
13+
[Xunit.Collection("PortReserver Collection")] // Avoid conflicts between different PortReserver consumers.
1314
public class BasicOverHttpTest
1415
{
1516
[Fact]

Diff for: test/System.Web.Http.SelfHost.Test/HttpSelfHostResponseTest.cs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace System.Web.Http.SelfHost
1414
{
15+
[Xunit.Collection("PortReserver Collection")] // Avoid conflicts between different PortReserver consumers.
1516
public class HttpSelfHostResponseTest
1617
{
1718
[Fact]

Diff for: test/System.Web.Http.SelfHost.Test/HttpSelfHostServerTest.cs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
namespace System.Web.Http.SelfHost
2020
{
21+
[Xunit.Collection("PortReserver Collection")] // Avoid conflicts between different PortReserver consumers.
2122
public class HttpSelfHostServerTest : IDisposable
2223
{
2324
private HttpSelfHostServer server = null;

0 commit comments

Comments
 (0)