Skip to content
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

Target .NET Standard 2.0 #103

Merged
merged 1 commit into from
Nov 22, 2017
Merged

Target .NET Standard 2.0 #103

merged 1 commit into from
Nov 22, 2017

Conversation

dougbu
Copy link
Member

@dougbu dougbu commented Nov 20, 2017

  • simplify .NET Standard projects and use Microsoft.NET.Sdk in test project
  • depend on Newtonsoft.Json v10 and Newtonsoft.Json.Bson v1 packages
    • Newtonsoft.Json v9.0.1 has a reduced API when targeting .NET Standard
    • adjust a few tests to handle changes between v9 and v10
  • test .NET Standard library on both .NET 4.6.1 and .NET Core 2.0
    • update test/Directory.Build.targets to handle testing with .NET Core; use it from Runtime.msbuild
    • adjust a few tests to handle .NET Core 2.0 differences and gaps
    • found and fixed a broken test in HttpValueCollectionTest

- simplify .NET Standard projects and use Microsoft.NET.Sdk in test project
- depend on Newtonsoft.Json v10 and Newtonsoft.Json.Bson v1 packages
  - Newtonsoft.Json v9.0.1 has a reduced API when targeting .NET Standard
  - adjust a few tests to handle changes between v9 and v10
- test .NET Standard library on both .NET 4.6.1 and .NET Core 2.0
  - update test/Directory.Build.targets to handle testing with .NET Core; use it from Runtime.msbuild
  - adjust a few tests to handle .NET Core 2.0 differences and gaps
  - found and fixed a broken test in `HttpValueCollectionTest`
<NoWarn>1591</NoWarn>
<TargetFrameworkVersion></TargetFrameworkVersion>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This oddity goes away with new condition in Directory.Build.props.

<Compile Include="..\System.Net.Http.Formatting.NetCore\MediaTypeHeaderValueExtensions.cs">
<Link>MediaTypeHeaderValueExtensions.cs</Link>

<Compile Include="..\System.Net.Http.Formatting\**\*.cs">
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed desktop project includes every source file in its folder.

<CodeAnalysisAdditionalOptions> /assemblycomparemode:StrongNameIgnoringVersion</CodeAnalysisAdditionalOptions>
<CodeAnalysisSearchGlobalAssemblyCache>false</CodeAnalysisSearchGlobalAssemblyCache>
<DefineConstants>$(DefineConstants);NETFX_CORE;ASPNETMVC;NOT_CLS_COMPLIANT;NETSTANDARD1_1</DefineConstants>
<RunCodeAnalysis>false</RunCodeAnalysis>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FxCop of this project is now completely redundant. In addition, even the newest command-line FxCop tool has trouble with .NET Standard libraries and the even-newer Roslyn analyzers can't load this particular library.

if (Type.GetType(_netCore20TypeName, throwOnError: false) != null)
{
// Treat .NET Core 2.0 as a .NET 4.5 superset though internal types are different.
return Platform.Net45;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for a runtime check whether test is running on .NET Core. Only the test assembly built for .NET Core is run on .NET Core.

<RootNamespace>System.Net.Http</RootNamespace>
<AssemblyName>System.Net.Http.Formatting.NetStandard.Test</AssemblyName>
<OutputPath>..\..\bin\$(Configuration)\Test\NetStandard\</OutputPath>
<DefineConstants>$(DefineConstants);NETFX_CORE</DefineConstants>
<OutputPath>..\..\bin\$(Configuration)\Test\</OutputPath>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test assemblies land in ..\..\bin\$(Configuration)\Test\net461 and ..\..\bin\$(Configuration)\Test\netcoreapp2.0.

@@ -458,6 +462,7 @@ IEnumerator<T> IEnumerable<T>.GetEnumerator()
[Serializable]
class SerializableType : IEquatable<SerializableType>
{
[JsonConstructor]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required when testing on .NET Core 2.0. But, does no harm anywhere…

@@ -202,29 +205,24 @@ private static void Create_CreateDoesntThrowTooManyValuesPrivate()
[Fact]
public void AddTooManyKeysThrows()
{
RunInIsolation(Create_CreateDoesntThrowTooManyValuesPrivate);
RunInIsolation(AddTooManyKeysThrowsPrivate);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test was previously a duplicate.

// Act && Assert
Assert.Throws<InvalidOperationException>(
() => collection.Add(_maxCollectionKeys.ToString(), _maxCollectionKeys.ToString()),
TooManyKeysError);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out the static keyword was all I need to get test working everywhere. But, updated test does the same thing and is easier to read.

@dougbu
Copy link
Member Author

dougbu commented Nov 20, 2017

This is most of the fix for #101. Remainder in CodeFlow…

@dougbu dougbu merged commit b1445a7 into master Nov 22, 2017
@dougbu
Copy link
Member Author

dougbu commented Nov 22, 2017

b1445a7

@dougbu dougbu deleted the dougbu/target.2.0 branch November 22, 2017 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants