Skip to content

Ease builds on CI and locally #364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
packages
NuGet.exe
_[Ss]cripts
*.binlog
*.exe
*.dll
*.nupkg
Expand Down
46 changes: 30 additions & 16 deletions Runtime.msbuild
Original file line number Diff line number Diff line change
Expand Up @@ -64,36 +64,50 @@
</Target>

<Target Name="RestorePackages" DependsOnTargets="DownloadNuGet">
<Message Text="Restoring NuGet packages..." Importance="High" />

<!-- NuGet.exe attempts to read src\System.Net.Http.Formatting.NetCore\System.Net.Http.Formatting.NetCore.csproj and imports fails without packages. -->
<Exec Command='"$(NuGetExe)" restore "src\System.Net.Http.Formatting.NetCore\packages.config" -PackagesDirectory packages -NonInteractive -Verbosity quiet -ConfigFile "$(MsBuildThisFileDirectory)\.nuget\NuGet.Config"' />
<ItemGroup>
<_NuGetPackagesAndSolutions Include="src\System.Net.Http.Formatting.NetCore\packages.config;
test\System.Net.Http.Formatting.NetCore.Test\packages.config;
Runtime.sln" />

<!-- Avoid restoring RuntimePortable.sln directly. -->
<_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' " />
</ItemGroup>

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

<!-- Pick the right Microsoft.Web.FxCop package to use and copy it to a standard location. -->
<Target Name="BuildTools">
<PropertyGroup>
<FxCopProjectLocation>$(MsBuildThisFileDirectory)tools\src\Microsoft.Web.FxCop\</FxCopProjectLocation>
<CustomFxCopRulesPath>$(MsBuildThisFileDirectory)packages\CustomFxCopRules</CustomFxCopRulesPath>
<FxCopProjectLocation>$(MSBuildThisFileDirectory)tools\src\Microsoft.Web.FxCop\</FxCopProjectLocation>
<CustomFxCopRulesPath>$(MSBuildThisFileDirectory)packages\CustomFxCopRules</CustomFxCopRulesPath>
</PropertyGroup>
<MsBuild
Condition=" '$(CodeAnalysis)' == 'true' "
Projects="$(FxCopProjectLocation)\Microsoft.Web.FxCop.csproj"
Properties="Configuration=Release;OutputPath=$(CustomFxCopRulesPath)" />
<MSBuild
Condition=" '$(CodeAnalysis)' == 'true' "
Projects="$(FxCopProjectLocation)\Microsoft.Web.FxCop.csproj"
Properties="Configuration=Release;OutputPath=$(CustomFxCopRulesPath)" />
</Target>

<Target Name="Build" DependsOnTargets="RestorePackages;BuildTools">
<!-- we need to batch the solution files since they both build Microsoft.TestCommon -->
<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)." />
<MakeDir Directories="bin\$(Configuration)" />
<MSBuild
Projects="@(SolutionsToBuild)"
BuildInParallel="%(SolutionsToBuild.BuildInParallel)"
Targets="Build"
Condition=" '%(SolutionsToBuild.Portable)' != 'true' or '$(BuildPortable)' == 'true' "
Properties="Configuration=$(Configuration);CodeAnalysis=$(CodeAnalysis);StyleCopEnabled=$(StyleCopEnabled);VisualStudioVersion=$(VisualStudioVersion)" />
Projects="@(SolutionsToBuild)"
BuildInParallel="%(SolutionsToBuild.BuildInParallel)"
Targets="Build"
Condition=" '%(SolutionsToBuild.Portable)' != 'true' or '$(BuildPortable)' == 'true' "
Properties="Configuration=$(Configuration);CodeAnalysis=$(CodeAnalysis);StyleCopEnabled=$(StyleCopEnabled);VisualStudioVersion=$(VisualStudioVersion)" />
</Target>

<Target Name="UnitTest" DependsOnTargets="CheckSkipStrongNames;Build">
Expand Down
4 changes: 3 additions & 1 deletion build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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" (
Expand Down
3 changes: 2 additions & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"sdk": {
"version": "2.1.523"
"version": "2.1.500",
"rollForward": "latestPatch"
}
}
7 changes: 7 additions & 0 deletions src/CodeAnalysisDictionary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@
<Word>ModelName</Word>
<Word>BSON</Word>
<Word>Untyped</Word>
<Word>Behavior</Word>
<Word>Callback</Word>
<Word>Canceled</Word>
<Word>Color</Word>
<Word>Fallback</Word>
<Word>Markup</Word>
<Word>Preflight</Word>
</Recognized>
<Compound>
<Term CompoundAlternate="WebPage">WebPage</Term>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<Link>Common\UriQueryUtility.cs</Link>
</Compile>

<Compile Include="..\System.Net.Http.Formatting\**\*.cs">
<Compile Include="..\System.Net.Http.Formatting\**\*.cs" Exclude="..\System.Net.Http.Formatting\obj\**\*.cs">
<Link>%(RecursiveDir)\%(Filename).cs</Link>
</Compile>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\System.Net.Http.Formatting.Test\**\*.cs">
<Compile Include="..\System.Net.Http.Formatting.Test\**\*.cs" Exclude="..\System.Net.Http.Formatting.Test\obj\**\*.cs">
<Link>%(RecursiveDir)\%(Filename).cs</Link>
</Compile>
</ItemGroup>
Expand Down
42 changes: 33 additions & 9 deletions test/System.Web.Http.Integration.Test/Tracing/TracingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,24 @@ private static IList<string> UnexpectedTraces(IList<ExpectedTraceRecord> 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;
}
Expand All @@ -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));
}
}

Expand All @@ -422,14 +434,26 @@ private static bool ConfirmTracingOrder(IList<ExpectedTraceRecord> 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);
Expand Down
22 changes: 21 additions & 1 deletion test/System.Web.Http.Owin.Test/HttpMessageHandlerAdapterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,6 @@ public async Task Invoke_BuildsUriWithHostAndPort()
[InlineData(@"-_.~+""<>^`{|}")]
// random unicode characters
[InlineData("激光這")]
[InlineData("%24")]
[InlineData("?#")]
public async Task Invoke_CreatesUri_ThatGeneratesCorrectlyDecodedStrings(string decodedId)
{
Expand All @@ -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()
{
Expand Down