From 666cc1d0616bf845a64c5c2be73998324eb005fc Mon Sep 17 00:00:00 2001 From: Doug Bunting <6431421+dougbu@users.noreply.github.com> Date: Tue, 28 Jun 2022 14:56:39 -0700 Subject: [PATCH 1/5] Ease builds on CI and locally - react to a smallish breaking change in newer Owin packages - gather more information when restoring RuntimePortable.sln - use `$(RestoreUseSkipNonexistentTargets)` as well - ignore binary logs - ensure the .NET Core 2.1 VS component is installed - allow use of any 2.1.5xx .NET SDK - add a few words to code analysis dictionary - exclude files generated for `net45` legacy projects don't cause problems when compiling for `netstandard2.0` - handle additional `ReflectionTypeLoadException`s when using the xUnit `msbuild` runner --- .gitignore | 1 + Runtime.msbuild | 11 +++-- build.cmd | 4 +- global.json | 3 +- src/CodeAnalysisDictionary.xml | 7 ++++ ...tem.Net.Http.Formatting.NetStandard.csproj | 2 +- ...et.Http.Formatting.NetStandard.Test.csproj | 2 +- .../Tracing/TracingTest.cs | 42 +++++++++++++++---- .../HttpMessageHandlerAdapterTest.cs | 2 +- 9 files changed, 57 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 11bf8ccc5..6cd7bfb72 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ packages NuGet.exe _[Ss]cripts +*.binlog *.exe *.dll *.nupkg diff --git a/Runtime.msbuild b/Runtime.msbuild index c3f2294e7..ecee150ff 100644 --- a/Runtime.msbuild +++ b/Runtime.msbuild @@ -67,9 +67,14 @@ - - - + + + diff --git a/build.cmd b/build.cmd index e49e2cfb8..270103785 100644 --- a/build.cmd +++ b/build.cmd @@ -26,7 +26,9 @@ if not exist %vswhere% ( ) set InstallDir= -for /f "usebackq tokens=*" %%i in (`%vswhere% -version ^[15^,16^) -latest -prerelease -products * -requires Microsoft.Component.MSBuild -property installationPath`) do ( +for /f "usebackq tokens=*" %%i in (`%vswhere% -version ^[15^,16^) -latest -prerelease -products * ^ + -requires Microsoft.Component.MSBuild -requires Microsoft.Net.Core.Component.SDK.2.1 ^ + -property installationPath`) do ( set InstallDir=%%i ) if exist "%InstallDir%\MSBuild\15.0\Bin\MSBuild.exe" ( diff --git a/global.json b/global.json index 3e8915949..9ddc9bf9c 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,6 @@ { "sdk": { - "version": "2.1.523" + "version": "2.1.500", + "rollForward": "latestPatch" } } diff --git a/src/CodeAnalysisDictionary.xml b/src/CodeAnalysisDictionary.xml index fdd4e0ea7..26ab4a8af 100644 --- a/src/CodeAnalysisDictionary.xml +++ b/src/CodeAnalysisDictionary.xml @@ -55,6 +55,13 @@ ModelName BSON Untyped + Behavior + Callback + Canceled + Color + Fallback + Markup + Preflight WebPage diff --git a/src/System.Net.Http.Formatting.NetStandard/System.Net.Http.Formatting.NetStandard.csproj b/src/System.Net.Http.Formatting.NetStandard/System.Net.Http.Formatting.NetStandard.csproj index 0211316d3..400278d86 100644 --- a/src/System.Net.Http.Formatting.NetStandard/System.Net.Http.Formatting.NetStandard.csproj +++ b/src/System.Net.Http.Formatting.NetStandard/System.Net.Http.Formatting.NetStandard.csproj @@ -41,7 +41,7 @@ Common\UriQueryUtility.cs - + %(RecursiveDir)\%(Filename).cs diff --git a/test/System.Net.Http.Formatting.NetStandard.Test/System.Net.Http.Formatting.NetStandard.Test.csproj b/test/System.Net.Http.Formatting.NetStandard.Test/System.Net.Http.Formatting.NetStandard.Test.csproj index 6cfb16e25..dbbca8480 100644 --- a/test/System.Net.Http.Formatting.NetStandard.Test/System.Net.Http.Formatting.NetStandard.Test.csproj +++ b/test/System.Net.Http.Formatting.NetStandard.Test/System.Net.Http.Formatting.NetStandard.Test.csproj @@ -15,7 +15,7 @@ - + %(RecursiveDir)\%(Filename).cs diff --git a/test/System.Web.Http.Integration.Test/Tracing/TracingTest.cs b/test/System.Web.Http.Integration.Test/Tracing/TracingTest.cs index 39e6cffd9..bc5d1618b 100644 --- a/test/System.Web.Http.Integration.Test/Tracing/TracingTest.cs +++ b/test/System.Web.Http.Integration.Test/Tracing/TracingTest.cs @@ -380,12 +380,24 @@ private static IList UnexpectedTraces(IList expecte // artifact specific to testing in VS. (Attempting to load all types from xunit.runner.visualstudio.testadapter.dll // fails with recent xUnit.net packages. The assembly references Microsoft.VisualStudio.TestPlatform.ObjectModel.dll // which is not available with xUnit.net 2.0.x.) + // + // Similarly, ignore records for the same exception to allow test to succeed when using the xUnit MSBuild runner. + // In that case, missing types may come from System.Web and Microsoft.Build.Utilities.v4.0 as well as xunit.runner.msbuild.net452. if (actualRecord.Operation == null && actualRecord.Exception is ReflectionTypeLoadException && actualRecord.Message != null && - actualRecord.Message.StartsWith( - "Exception thrown while getting types from 'xunit.runner.visualstudio.testadapter, ", - StringComparison.Ordinal)) + (actualRecord.Message.StartsWith( + "Exception thrown while getting types from 'xunit.runner.visualstudio.testadapter, ", + StringComparison.Ordinal) || + actualRecord.Message.StartsWith( + "Exception thrown while getting types from 'xunit.runner.msbuild.", + StringComparison.Ordinal) || + actualRecord.Message.StartsWith( + "Exception thrown while getting types from 'System.Web, ", + StringComparison.Ordinal) || + actualRecord.Message.StartsWith( + "Exception thrown while getting types from 'Microsoft.Build.Utilities.", + StringComparison.Ordinal))) { continue; } @@ -397,8 +409,8 @@ actualRecord.Exception is ReflectionTypeLoadException && if (expectedTrace == null) { - unexpected.Add(string.Format("kind={0} category={1}, operator={2}, operation={3}", - actualRecord.Kind, actualRecord.Category, actualRecord.Operator, actualRecord.Operation)); + unexpected.Add(string.Format("kind={0} category={1}, operator={2}, operation={3}, message={4}", + actualRecord.Kind, actualRecord.Category, actualRecord.Operator, actualRecord.Operation, actualRecord.Message)); } } @@ -422,14 +434,26 @@ private static bool ConfirmTracingOrder(IList expectedRecor // artifact specific to testing in VS. (Attempting to load all types from xunit.runner.visualstudio.testadapter.dll // fails with recent xUnit.net packages. The assembly references Microsoft.VisualStudio.TestPlatform.ObjectModel.dll // which is not available with xUnit.net 2.0.x.) + // + // Similarly, ignore records for the same exception to allow test to succeed when using the xUnit MSBuild runner. + // In that case, missing types may come from System.Web and Microsoft.Build.Utilities.v4.0 as well as xunit.runner.msbuild.net452. var actualRecord = actualRecords.ElementAtOrDefault(traceBeginPos); - if (actualRecord != null && + while (actualRecord != null && actualRecord.Operation == null && actualRecord.Exception is ReflectionTypeLoadException && actualRecord.Message != null && - actualRecord.Message.StartsWith( - "Exception thrown while getting types from 'xunit.runner.visualstudio.testadapter, ", - StringComparison.Ordinal)) + (actualRecord.Message.StartsWith( + "Exception thrown while getting types from 'xunit.runner.visualstudio.testadapter, ", + StringComparison.Ordinal) || + actualRecord.Message.StartsWith( + "Exception thrown while getting types from 'xunit.runner.msbuild.", + StringComparison.Ordinal) || + actualRecord.Message.StartsWith( + "Exception thrown while getting types from 'System.Web, ", + StringComparison.Ordinal) || + actualRecord.Message.StartsWith( + "Exception thrown while getting types from 'Microsoft.Build.Utilities.", + StringComparison.Ordinal))) { traceBeginPos++; actualRecord = actualRecords.ElementAtOrDefault(traceBeginPos); diff --git a/test/System.Web.Http.Owin.Test/HttpMessageHandlerAdapterTest.cs b/test/System.Web.Http.Owin.Test/HttpMessageHandlerAdapterTest.cs index 8ddfce69d..602650e27 100644 --- a/test/System.Web.Http.Owin.Test/HttpMessageHandlerAdapterTest.cs +++ b/test/System.Web.Http.Owin.Test/HttpMessageHandlerAdapterTest.cs @@ -429,7 +429,7 @@ public async Task Invoke_BuildsUriWithHostAndPort() [InlineData(@"-_.~+""<>^`{|}")] // random unicode characters [InlineData("激光這")] - [InlineData("%24")] + [InlineData("%24", Skip="Decoded to '$' at the moment. !!! Investigate !!!")] [InlineData("?#")] public async Task Invoke_CreatesUri_ThatGeneratesCorrectlyDecodedStrings(string decodedId) { From 52a39af4904a73edd20c048b8e69ebcdb8a8bc6c Mon Sep 17 00:00:00 2001 From: Doug Bunting <6431421+dougbu@users.noreply.github.com> Date: Fri, 18 Nov 2022 15:42:34 -0800 Subject: [PATCH 2/5] !fixup! Wrap long command lines --- Runtime.msbuild | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Runtime.msbuild b/Runtime.msbuild index ecee150ff..a852a7c53 100644 --- a/Runtime.msbuild +++ b/Runtime.msbuild @@ -67,13 +67,13 @@ - - From 01614f6b0b6cf3cbc78f1a33aa7d1daf289d8cb8 Mon Sep 17 00:00:00 2001 From: Doug Bunting <6431421+dougbu@users.noreply.github.com> Date: Fri, 18 Nov 2022 16:33:35 -0800 Subject: [PATCH 3/5] !fixup! Another `msbuild` correction --- Runtime.msbuild | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Runtime.msbuild b/Runtime.msbuild index a852a7c53..941faf9ab 100644 --- a/Runtime.msbuild +++ b/Runtime.msbuild @@ -73,8 +73,8 @@ + -Verbosity normal -ConfigFile "$(MsBuildThisFileDirectory)\.nuget\NuGet.Config"' + EnvironmentVariables="RestoreUseSkipNonexistentTargets=true" /> From aca8161f5986aceaa1b9142f62865be393e7800f Mon Sep 17 00:00:00 2001 From: Doug Bunting <6431421+dougbu@users.noreply.github.com> Date: Fri, 18 Nov 2022 16:33:58 -0800 Subject: [PATCH 4/5] Add new test of `%` decoding to URI --- .../HttpMessageHandlerAdapterTest.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/test/System.Web.Http.Owin.Test/HttpMessageHandlerAdapterTest.cs b/test/System.Web.Http.Owin.Test/HttpMessageHandlerAdapterTest.cs index 602650e27..b8b25e30f 100644 --- a/test/System.Web.Http.Owin.Test/HttpMessageHandlerAdapterTest.cs +++ b/test/System.Web.Http.Owin.Test/HttpMessageHandlerAdapterTest.cs @@ -429,7 +429,6 @@ public async Task Invoke_BuildsUriWithHostAndPort() [InlineData(@"-_.~+""<>^`{|}")] // random unicode characters [InlineData("激光這")] - [InlineData("%24", Skip="Decoded to '$' at the moment. !!! Investigate !!!")] [InlineData("?#")] public async Task Invoke_CreatesUri_ThatGeneratesCorrectlyDecodedStrings(string decodedId) { @@ -447,6 +446,27 @@ public async Task Invoke_CreatesUri_ThatGeneratesCorrectlyDecodedStrings(string Assert.Equal(decodedId, routeData.Values["id"]); } + [Theory] + [InlineData("%24", "$")] + [InlineData("%28%29", "()")] + [InlineData("%5B%5D", "[]")] + [InlineData("%7B%7D", "{}")] + public async Task Invoke_CreatesUri_ContainingCorrectlyDecodedStrings(string encoded, string decoded) + { + var handler = CreateOKHandlerStub(); + var bufferPolicySelector = CreateBufferPolicySelector(bufferInput: false, bufferOutput: false); + var environment = CreateOwinEnvironment("GET", "http", "localhost", "/vroot", "/api/customers/" + encoded); + var options = CreateValidOptions(handler, bufferPolicySelector); + var adapter = CreateProductUnderTest(options); + var route = new HttpRoute("api/customers/{id}"); + + await adapter.Invoke(new OwinContext(environment)); + IHttpRouteData routeData = route.GetRouteData("/vroot", handler.Request); + + Assert.NotNull(routeData); + Assert.Equal(decoded, routeData.Values["id"]); + } + [Fact] public async Task Invoke_AddsRequestHeadersToRequestMessage() { From 747a62de4d11563cf99d4f2fe68e46f10e5ef42a Mon Sep 17 00:00:00 2001 From: Doug Bunting <6431421+dougbu@users.noreply.github.com> Date: Fri, 18 Nov 2022 17:25:12 -0800 Subject: [PATCH 5/5] Do not restore RuntimePortable.sln directly nits: - capitalize "MSBuild" consistently - reduce indentation slightly --- Runtime.msbuild | 49 +++++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/Runtime.msbuild b/Runtime.msbuild index 941faf9ab..2e785ab2e 100644 --- a/Runtime.msbuild +++ b/Runtime.msbuild @@ -64,29 +64,38 @@ - - - - + + <_NuGetPackagesAndSolutions Include="src\System.Net.Http.Formatting.NetCore\packages.config; + test\System.Net.Http.Formatting.NetCore.Test\packages.config; + Runtime.sln" /> + + + <_NuGetPackagesAndSolutions Include="src\System.Net.Http.Formatting.NetCore\packages.config; + test\System.Net.Http.Formatting.NetCore.Test\packages.config" + Condition=" '$(BuildPortable)' == 'true' " /> + <_ProjectsToRestore Include="src\System.Net.Http.Formatting.NetStandard\System.Net.Http.Formatting.NetStandard.csproj; + test\System.Net.Http.Formatting.NetStandard.Test\System.Net.Http.Formatting.NetStandard.Test.csproj" + Condition=" '$(BuildPortable)' == 'true' " /> + - + -Verbosity normal -ConfigFile "$(MSBuildThisFileDirectory)\.nuget\NuGet.Config"' /> + - $(MsBuildThisFileDirectory)tools\src\Microsoft.Web.FxCop\ - $(MsBuildThisFileDirectory)packages\CustomFxCopRules + $(MSBuildThisFileDirectory)tools\src\Microsoft.Web.FxCop\ + $(MSBuildThisFileDirectory)packages\CustomFxCopRules - + @@ -94,11 +103,11 @@ + Projects="@(SolutionsToBuild)" + BuildInParallel="%(SolutionsToBuild.BuildInParallel)" + Targets="Build" + Condition=" '%(SolutionsToBuild.Portable)' != 'true' or '$(BuildPortable)' == 'true' " + Properties="Configuration=$(Configuration);CodeAnalysis=$(CodeAnalysis);StyleCopEnabled=$(StyleCopEnabled);VisualStudioVersion=$(VisualStudioVersion)" />