Skip to content

Commit eae5661

Browse files
authored
Ease builds on CI and locally (#364)
react to a smallish breaking change in newer Owin packages - add new test of `%` decoding to URI - do not restore RuntimePortable.sln directly - NuGet.exe is no longer happy w/ that solution - 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 nits: - capitalize "MSBuild" consistently - reduce indentation slightly
1 parent cd01862 commit eae5661

File tree

9 files changed

+99
-30
lines changed

9 files changed

+99
-30
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
packages
99
NuGet.exe
1010
_[Ss]cripts
11+
*.binlog
1112
*.exe
1213
*.dll
1314
*.nupkg

Runtime.msbuild

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,36 +64,50 @@
6464
</Target>
6565

6666
<Target Name="RestorePackages" DependsOnTargets="DownloadNuGet">
67-
<Message Text="Restoring NuGet packages..." Importance="High" />
68-
69-
<!-- NuGet.exe attempts to read src\System.Net.Http.Formatting.NetCore\System.Net.Http.Formatting.NetCore.csproj and imports fails without packages. -->
70-
<Exec Command='"$(NuGetExe)" restore "src\System.Net.Http.Formatting.NetCore\packages.config" -PackagesDirectory packages -NonInteractive -Verbosity quiet -ConfigFile "$(MsBuildThisFileDirectory)\.nuget\NuGet.Config"' />
67+
<ItemGroup>
68+
<_NuGetPackagesAndSolutions Include="src\System.Net.Http.Formatting.NetCore\packages.config;
69+
test\System.Net.Http.Formatting.NetCore.Test\packages.config;
70+
Runtime.sln" />
71+
72+
<!-- Avoid restoring RuntimePortable.sln directly. -->
73+
<_NuGetPackagesAndSolutions Include="src\System.Net.Http.Formatting.NetCore\packages.config;
74+
test\System.Net.Http.Formatting.NetCore.Test\packages.config"
75+
Condition=" '$(BuildPortable)' == 'true' " />
76+
<_ProjectsToRestore Include="src\System.Net.Http.Formatting.NetStandard\System.Net.Http.Formatting.NetStandard.csproj;
77+
test\System.Net.Http.Formatting.NetStandard.Test\System.Net.Http.Formatting.NetStandard.Test.csproj"
78+
Condition=" '$(BuildPortable)' == 'true' " />
79+
</ItemGroup>
7180

72-
<Exec Command='"$(NuGetExe)" restore "%(SolutionsToBuild.Identity)" -PackagesDirectory packages -NonInteractive -Verbosity quiet -ConfigFile "$(MsBuildThisFileDirectory)\.nuget\NuGet.Config"' />
81+
<Message Text="Restoring NuGet packages..." Importance="High" />
82+
<Exec Command='"$(NuGetExe)" restore "%(_NuGetPackagesAndSolutions.Identity)" ^
83+
-PackagesDirectory packages -NonInteractive ^
84+
-Verbosity normal -ConfigFile "$(MSBuildThisFileDirectory)\.nuget\NuGet.Config"' />
85+
<MSBuild Projects="@(_ProjectsToRestore)" Targets="Restore" Properties="Configuration=$(Configuration)"
86+
Condition=" '$(BuildPortable)' == 'true' " />
7387
</Target>
7488

7589
<!-- Pick the right Microsoft.Web.FxCop package to use and copy it to a standard location. -->
7690
<Target Name="BuildTools">
7791
<PropertyGroup>
78-
<FxCopProjectLocation>$(MsBuildThisFileDirectory)tools\src\Microsoft.Web.FxCop\</FxCopProjectLocation>
79-
<CustomFxCopRulesPath>$(MsBuildThisFileDirectory)packages\CustomFxCopRules</CustomFxCopRulesPath>
92+
<FxCopProjectLocation>$(MSBuildThisFileDirectory)tools\src\Microsoft.Web.FxCop\</FxCopProjectLocation>
93+
<CustomFxCopRulesPath>$(MSBuildThisFileDirectory)packages\CustomFxCopRules</CustomFxCopRulesPath>
8094
</PropertyGroup>
81-
<MsBuild
82-
Condition=" '$(CodeAnalysis)' == 'true' "
83-
Projects="$(FxCopProjectLocation)\Microsoft.Web.FxCop.csproj"
84-
Properties="Configuration=Release;OutputPath=$(CustomFxCopRulesPath)" />
95+
<MSBuild
96+
Condition=" '$(CodeAnalysis)' == 'true' "
97+
Projects="$(FxCopProjectLocation)\Microsoft.Web.FxCop.csproj"
98+
Properties="Configuration=Release;OutputPath=$(CustomFxCopRulesPath)" />
8599
</Target>
86100

87101
<Target Name="Build" DependsOnTargets="RestorePackages;BuildTools">
88102
<!-- we need to batch the solution files since they both build Microsoft.TestCommon -->
89103
<Error Condition=" '$(CodeAnalysis)' == 'true' and '$(Configuration)' == 'Release' " Text="Unable to run code analysis in Release configuration. Release assemblies do not include SuppressMessage attributes (so code analysis would always fail with the errors that are normally suppressed)." />
90104
<MakeDir Directories="bin\$(Configuration)" />
91105
<MSBuild
92-
Projects="@(SolutionsToBuild)"
93-
BuildInParallel="%(SolutionsToBuild.BuildInParallel)"
94-
Targets="Build"
95-
Condition=" '%(SolutionsToBuild.Portable)' != 'true' or '$(BuildPortable)' == 'true' "
96-
Properties="Configuration=$(Configuration);CodeAnalysis=$(CodeAnalysis);StyleCopEnabled=$(StyleCopEnabled);VisualStudioVersion=$(VisualStudioVersion)" />
106+
Projects="@(SolutionsToBuild)"
107+
BuildInParallel="%(SolutionsToBuild.BuildInParallel)"
108+
Targets="Build"
109+
Condition=" '%(SolutionsToBuild.Portable)' != 'true' or '$(BuildPortable)' == 'true' "
110+
Properties="Configuration=$(Configuration);CodeAnalysis=$(CodeAnalysis);StyleCopEnabled=$(StyleCopEnabled);VisualStudioVersion=$(VisualStudioVersion)" />
97111
</Target>
98112

99113
<Target Name="UnitTest" DependsOnTargets="CheckSkipStrongNames;Build">

build.cmd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ if not exist %vswhere% (
2626
)
2727

2828
set InstallDir=
29-
for /f "usebackq tokens=*" %%i in (`%vswhere% -version ^[15^,16^) -latest -prerelease -products * -requires Microsoft.Component.MSBuild -property installationPath`) do (
29+
for /f "usebackq tokens=*" %%i in (`%vswhere% -version ^[15^,16^) -latest -prerelease -products * ^
30+
-requires Microsoft.Component.MSBuild -requires Microsoft.Net.Core.Component.SDK.2.1 ^
31+
-property installationPath`) do (
3032
set InstallDir=%%i
3133
)
3234
if exist "%InstallDir%\MSBuild\15.0\Bin\MSBuild.exe" (

global.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"sdk": {
3-
"version": "2.1.523"
3+
"version": "2.1.500",
4+
"rollForward": "latestPatch"
45
}
56
}

src/CodeAnalysisDictionary.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@
5555
<Word>ModelName</Word>
5656
<Word>BSON</Word>
5757
<Word>Untyped</Word>
58+
<Word>Behavior</Word>
59+
<Word>Callback</Word>
60+
<Word>Canceled</Word>
61+
<Word>Color</Word>
62+
<Word>Fallback</Word>
63+
<Word>Markup</Word>
64+
<Word>Preflight</Word>
5865
</Recognized>
5966
<Compound>
6067
<Term CompoundAlternate="WebPage">WebPage</Term>

src/System.Net.Http.Formatting.NetStandard/System.Net.Http.Formatting.NetStandard.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<Link>Common\UriQueryUtility.cs</Link>
4242
</Compile>
4343

44-
<Compile Include="..\System.Net.Http.Formatting\**\*.cs">
44+
<Compile Include="..\System.Net.Http.Formatting\**\*.cs" Exclude="..\System.Net.Http.Formatting\obj\**\*.cs">
4545
<Link>%(RecursiveDir)\%(Filename).cs</Link>
4646
</Compile>
4747
</ItemGroup>

test/System.Net.Http.Formatting.NetStandard.Test/System.Net.Http.Formatting.NetStandard.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
1616
</ItemGroup>
1717
<ItemGroup>
18-
<Compile Include="..\System.Net.Http.Formatting.Test\**\*.cs">
18+
<Compile Include="..\System.Net.Http.Formatting.Test\**\*.cs" Exclude="..\System.Net.Http.Formatting.Test\obj\**\*.cs">
1919
<Link>%(RecursiveDir)\%(Filename).cs</Link>
2020
</Compile>
2121
</ItemGroup>

test/System.Web.Http.Integration.Test/Tracing/TracingTest.cs

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,24 @@ private static IList<string> UnexpectedTraces(IList<ExpectedTraceRecord> expecte
380380
// artifact specific to testing in VS. (Attempting to load all types from xunit.runner.visualstudio.testadapter.dll
381381
// fails with recent xUnit.net packages. The assembly references Microsoft.VisualStudio.TestPlatform.ObjectModel.dll
382382
// which is not available with xUnit.net 2.0.x.)
383+
//
384+
// Similarly, ignore records for the same exception to allow test to succeed when using the xUnit MSBuild runner.
385+
// In that case, missing types may come from System.Web and Microsoft.Build.Utilities.v4.0 as well as xunit.runner.msbuild.net452.
383386
if (actualRecord.Operation == null &&
384387
actualRecord.Exception is ReflectionTypeLoadException &&
385388
actualRecord.Message != null &&
386-
actualRecord.Message.StartsWith(
387-
"Exception thrown while getting types from 'xunit.runner.visualstudio.testadapter, ",
388-
StringComparison.Ordinal))
389+
(actualRecord.Message.StartsWith(
390+
"Exception thrown while getting types from 'xunit.runner.visualstudio.testadapter, ",
391+
StringComparison.Ordinal) ||
392+
actualRecord.Message.StartsWith(
393+
"Exception thrown while getting types from 'xunit.runner.msbuild.",
394+
StringComparison.Ordinal) ||
395+
actualRecord.Message.StartsWith(
396+
"Exception thrown while getting types from 'System.Web, ",
397+
StringComparison.Ordinal) ||
398+
actualRecord.Message.StartsWith(
399+
"Exception thrown while getting types from 'Microsoft.Build.Utilities.",
400+
StringComparison.Ordinal)))
389401
{
390402
continue;
391403
}
@@ -397,8 +409,8 @@ actualRecord.Exception is ReflectionTypeLoadException &&
397409

398410
if (expectedTrace == null)
399411
{
400-
unexpected.Add(string.Format("kind={0} category={1}, operator={2}, operation={3}",
401-
actualRecord.Kind, actualRecord.Category, actualRecord.Operator, actualRecord.Operation));
412+
unexpected.Add(string.Format("kind={0} category={1}, operator={2}, operation={3}, message={4}",
413+
actualRecord.Kind, actualRecord.Category, actualRecord.Operator, actualRecord.Operation, actualRecord.Message));
402414
}
403415
}
404416

@@ -422,14 +434,26 @@ private static bool ConfirmTracingOrder(IList<ExpectedTraceRecord> expectedRecor
422434
// artifact specific to testing in VS. (Attempting to load all types from xunit.runner.visualstudio.testadapter.dll
423435
// fails with recent xUnit.net packages. The assembly references Microsoft.VisualStudio.TestPlatform.ObjectModel.dll
424436
// which is not available with xUnit.net 2.0.x.)
437+
//
438+
// Similarly, ignore records for the same exception to allow test to succeed when using the xUnit MSBuild runner.
439+
// In that case, missing types may come from System.Web and Microsoft.Build.Utilities.v4.0 as well as xunit.runner.msbuild.net452.
425440
var actualRecord = actualRecords.ElementAtOrDefault(traceBeginPos);
426-
if (actualRecord != null &&
441+
while (actualRecord != null &&
427442
actualRecord.Operation == null &&
428443
actualRecord.Exception is ReflectionTypeLoadException &&
429444
actualRecord.Message != null &&
430-
actualRecord.Message.StartsWith(
431-
"Exception thrown while getting types from 'xunit.runner.visualstudio.testadapter, ",
432-
StringComparison.Ordinal))
445+
(actualRecord.Message.StartsWith(
446+
"Exception thrown while getting types from 'xunit.runner.visualstudio.testadapter, ",
447+
StringComparison.Ordinal) ||
448+
actualRecord.Message.StartsWith(
449+
"Exception thrown while getting types from 'xunit.runner.msbuild.",
450+
StringComparison.Ordinal) ||
451+
actualRecord.Message.StartsWith(
452+
"Exception thrown while getting types from 'System.Web, ",
453+
StringComparison.Ordinal) ||
454+
actualRecord.Message.StartsWith(
455+
"Exception thrown while getting types from 'Microsoft.Build.Utilities.",
456+
StringComparison.Ordinal)))
433457
{
434458
traceBeginPos++;
435459
actualRecord = actualRecords.ElementAtOrDefault(traceBeginPos);

test/System.Web.Http.Owin.Test/HttpMessageHandlerAdapterTest.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,6 @@ public async Task Invoke_BuildsUriWithHostAndPort()
429429
[InlineData(@"-_.~+""<>^`{|}")]
430430
// random unicode characters
431431
[InlineData("激光這")]
432-
[InlineData("%24")]
433432
[InlineData("?#")]
434433
public async Task Invoke_CreatesUri_ThatGeneratesCorrectlyDecodedStrings(string decodedId)
435434
{
@@ -447,6 +446,27 @@ public async Task Invoke_CreatesUri_ThatGeneratesCorrectlyDecodedStrings(string
447446
Assert.Equal(decodedId, routeData.Values["id"]);
448447
}
449448

449+
[Theory]
450+
[InlineData("%24", "$")]
451+
[InlineData("%28%29", "()")]
452+
[InlineData("%5B%5D", "[]")]
453+
[InlineData("%7B%7D", "{}")]
454+
public async Task Invoke_CreatesUri_ContainingCorrectlyDecodedStrings(string encoded, string decoded)
455+
{
456+
var handler = CreateOKHandlerStub();
457+
var bufferPolicySelector = CreateBufferPolicySelector(bufferInput: false, bufferOutput: false);
458+
var environment = CreateOwinEnvironment("GET", "http", "localhost", "/vroot", "/api/customers/" + encoded);
459+
var options = CreateValidOptions(handler, bufferPolicySelector);
460+
var adapter = CreateProductUnderTest(options);
461+
var route = new HttpRoute("api/customers/{id}");
462+
463+
await adapter.Invoke(new OwinContext(environment));
464+
IHttpRouteData routeData = route.GetRouteData("/vroot", handler.Request);
465+
466+
Assert.NotNull(routeData);
467+
Assert.Equal(decoded, routeData.Values["id"]);
468+
}
469+
450470
[Fact]
451471
public async Task Invoke_AddsRequestHeadersToRequestMessage()
452472
{

0 commit comments

Comments
 (0)