Skip to content

Commit

Permalink
Added support for .NET Standard
Browse files Browse the repository at this point in the history
  • Loading branch information
niemyjski committed Jul 20, 2016
1 parent 4101c14 commit e46e5ec
Show file tree
Hide file tree
Showing 14 changed files with 462 additions and 429 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Expand Up @@ -4,4 +4,9 @@ obj/
TestResults/
*.csproj.user
*.suo
*.nupkg
*.nupkg

# project.json
*.lock.json
.vs
*.user
28 changes: 15 additions & 13 deletions Semver.sln
@@ -1,30 +1,32 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Semver", "Semver\Semver.csproj", "{95B2542C-E371-4AB4-9E2D-B2665CBBD629}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Semver.Test", "Semver.Test\Semver.Test.csproj", "{EAE17B6B-5380-4017-8046-1757EB77DF53}"
EndProject
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{AC069663-5FE9-438A-A9F4-C5293D695D98}"
ProjectSection(SolutionItems) = preProject
License.txt = License.txt
README.md = README.md
EndProjectSection
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Semver", "src\Semver\Semver.xproj", "{DA3E84C8-A960-420C-A85A-718005AACC36}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Semver.Test", "test\Semver.Test\Semver.Test.xproj", "{DA03E4C4-CB6C-447B-B617-15B5689E9029}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{95B2542C-E371-4AB4-9E2D-B2665CBBD629}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{95B2542C-E371-4AB4-9E2D-B2665CBBD629}.Debug|Any CPU.Build.0 = Debug|Any CPU
{95B2542C-E371-4AB4-9E2D-B2665CBBD629}.Release|Any CPU.ActiveCfg = Release|Any CPU
{95B2542C-E371-4AB4-9E2D-B2665CBBD629}.Release|Any CPU.Build.0 = Release|Any CPU
{EAE17B6B-5380-4017-8046-1757EB77DF53}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EAE17B6B-5380-4017-8046-1757EB77DF53}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EAE17B6B-5380-4017-8046-1757EB77DF53}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EAE17B6B-5380-4017-8046-1757EB77DF53}.Release|Any CPU.Build.0 = Release|Any CPU
{DA3E84C8-A960-420C-A85A-718005AACC36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DA3E84C8-A960-420C-A85A-718005AACC36}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DA3E84C8-A960-420C-A85A-718005AACC36}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DA3E84C8-A960-420C-A85A-718005AACC36}.Release|Any CPU.Build.0 = Release|Any CPU
{DA03E4C4-CB6C-447B-B617-15B5689E9029}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DA03E4C4-CB6C-447B-B617-15B5689E9029}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DA03E4C4-CB6C-447B-B617-15B5689E9029}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DA03E4C4-CB6C-447B-B617-15B5689E9029}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
9 changes: 9 additions & 0 deletions global.json
@@ -0,0 +1,9 @@
{
"projects": [
"src",
"test"
],
"sdk": {
"version": "1.0.0-preview2-003121"
}
}
3 changes: 2 additions & 1 deletion src/Semver/Properties/AssemblyInfo.cs
Expand Up @@ -7,6 +7,7 @@
[assembly: AssemblyCopyright("Copyright © 2013 Max Hauser")]
[assembly: ComVisible(false)]
[assembly: Guid("e208ca67-5b59-45d9-a29a-7f30137d3beb")]

[assembly: AssemblyVersion("1.1.2")]
[assembly: AssemblyFileVersion("1.1.2")]
[assembly: AssemblyInformationalVersion("1.1.2")]
[assembly: AssemblyInformationalVersion("1.1.2")]
58 changes: 55 additions & 3 deletions src/Semver/SemVersion.cs
@@ -1,7 +1,9 @@
using System;
using System.Globalization;
#if !NETSTANDARD
using System.Runtime.Serialization;
using System.Security.Permissions;
#endif
using System.Text.RegularExpressions;

namespace Semver
Expand All @@ -10,17 +12,26 @@ namespace Semver
/// A semantic version implementation.
/// Conforms to v2.0.0 of http://semver.org/
/// </summary>
#if NETSTANDARD
public sealed class SemVersion : IComparable<SemVersion>, IComparable
#else
[Serializable]
public sealed class SemVersion : IComparable<SemVersion>, IComparable, ISerializable
#endif
{
static Regex parseEx =
new Regex(@"^(?<major>\d+)" +
@"(\.(?<minor>\d+))?" +
@"(\.(?<patch>\d+))?" +
@"(\-(?<pre>[0-9A-Za-z\-\.]+))?" +
@"(\+(?<build>[0-9A-Za-z\-\.]+))?$",
#if NETSTANDARD
RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture);
#else
RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.ExplicitCapture);
#endif

#if !NETSTANDARD
/// <summary>
/// Initializes a new instance of the <see cref="SemVersion" /> class.
/// </summary>
Expand All @@ -37,6 +48,7 @@ private SemVersion(SerializationInfo info, StreamingContext context)
Prerelease = semVersion.Prerelease;
Build = semVersion.Build;
}
#endif

/// <summary>
/// Initializes a new instance of the <see cref="SemVersion" /> class.
Expand All @@ -52,9 +64,14 @@ public SemVersion(int major, int minor = 0, int patch = 0, string prerelease = "
this.Minor = minor;
this.Patch = patch;

#if NETSTANDARD
this.Prerelease = String.Empty;
this.Build = String.Empty;
#else
// strings are interned to be able to compare by reference in equals method
this.Prerelease = String.Intern(prerelease ?? "");
this.Build = String.Intern(build ?? "");
#endif
}

/// <summary>
Expand All @@ -64,7 +81,8 @@ public SemVersion(int major, int minor = 0, int patch = 0, string prerelease = "
/// the Major, Minor, Patch and Build properties.</param>
public SemVersion(Version version)
{
version = version ?? new Version();
if (version == null)
throw new ArgumentNullException("version");

this.Major = version.Major;
this.Minor = version.Minor;
Expand All @@ -74,15 +92,27 @@ public SemVersion(Version version)
this.Patch = version.Revision;
}

#if NETSTANDARD
this.Prerelease = String.Empty;
#else
this.Prerelease = String.Intern("");
#endif

if (version.Build > 0)
{
#if NETSTANDARD
this.Build = version.Build.ToString();
#else
this.Build = String.Intern(version.Build.ToString());
#endif
}
else
{
#if NETSTANDARD
this.Build = String.Empty;
#else
this.Build = String.Intern("");
#endif
}
}

Expand All @@ -99,21 +129,41 @@ public static SemVersion Parse(string version, bool strict = false)
if (!match.Success)
throw new ArgumentException("Invalid version.", "version");

#if NETSTANDARD
var major = Int32.Parse(match.Groups["major"].Value);
#else
var major = Int32.Parse(match.Groups["major"].Value, CultureInfo.InvariantCulture);
#endif

var minorMatch = match.Groups["minor"];
int minor = 0;
if (minorMatch.Success)
if (minorMatch.Success)
{
#if NETSTANDARD
minor = Int32.Parse(minorMatch.Value);
#else
minor = Int32.Parse(minorMatch.Value, CultureInfo.InvariantCulture);
#endif
}
else if (strict)
{
throw new InvalidOperationException("Invalid version (no minor version given in strict mode)");
}

var patchMatch = match.Groups["patch"];
int patch = 0;
if (patchMatch.Success)
{
#if NETSTANDARD
patch = Int32.Parse(patchMatch.Value);
#else
patch = Int32.Parse(patchMatch.Value, CultureInfo.InvariantCulture);
else if (strict)
#endif
}
else if (strict)
{
throw new InvalidOperationException("Invalid version (no patch version given in strict mode)");
}

var prerelease = match.Groups["pre"].Value;
var build = match.Groups["build"].Value;
Expand Down Expand Up @@ -418,12 +468,14 @@ public override int GetHashCode()
}
}

#if !NETSTANDARD
[SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null) throw new ArgumentNullException("info");
info.AddValue("SemVersion", ToString());
}
#endif

/// <summary>
/// Implicit conversion from string to SemVersion.
Expand Down
51 changes: 0 additions & 51 deletions src/Semver/Semver.csproj

This file was deleted.

23 changes: 0 additions & 23 deletions src/Semver/Semver.nuspec

This file was deleted.

19 changes: 19 additions & 0 deletions src/Semver/Semver.xproj
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>da3e84c8-a960-420c-a85a-718005aacc36</ProjectGuid>
<RootNamespace>Semver</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
53 changes: 53 additions & 0 deletions src/Semver/project.json
@@ -0,0 +1,53 @@
{
"version": "99.99.99-dev",
"title": "Semantic versioning",
"description": "A semver implementation in .Net based on the v2.0.0 of the spec found at http://semver.org/.",
"authors": [ "Max Hauser" ],
"copyright": "Copyright (c) 2013",
"packOptions": {
"tags": [ "semver", "semantic", "version" ],
"owners": [ "Max Hauser" ],
"projectUrl": "https://github.com/maxhauser/semver",
"releaseNotes": "https://github.com/maxhauser/semver/releases",
"licenseUrl": "http://max.mit-license.org/",
"repository": {
"type": "git",
"url": "https://github.com/maxhauser/semver"
}
},
"buildOptions": {
"debugType": "portable",
"nowarn": [
"CS1591"
],
"optimize": true,
"warningsAsErrors": true,
"xmlDoc": true
},
"frameworks": {
"netstandard1.1": {
"buildOptions": {
"define": [ "NETSTANDARD", "NETSTANDARD1_1" ]
},
"dependencies": {
"System.Runtime": "4.1.0",
"System.Runtime.Extensions": "4.1.0",
"System.Runtime.InteropServices": "4.1.0",
"System.Text.RegularExpressions": "4.1.0"
}
},
"net452": {
"buildOptions": {
"define": [ "NET45" ]
},
"frameworkAssemblies": {
"System.Runtime": {
"type": "build"
},
"System.Threading.Tasks": {
"type": "build"
}
}
}
}
}

0 comments on commit e46e5ec

Please sign in to comment.