Skip to content

Commit 120d8b6

Browse files
committed
GitTools#1175 - First pass at GitVersionCore on netstadard - wip.
Haven't been able to resolve some compilation errors yet due to lack of replacemnt API's on netstandard.
1 parent c8332ef commit 120d8b6

27 files changed

+341
-211
lines changed

src/GitVersion.sln

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 14
4-
VisualStudioVersion = 14.0.25420.1
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26430.16
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitVersionExe", "GitVersionExe\GitVersionExe.csproj", "{C3578A7B-09A6-4444-9383-0DEAFA4958BD}"
77
EndProject
@@ -26,6 +26,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
2626
..\GitVersion.yml = ..\GitVersion.yml
2727
..\LICENSE = ..\LICENSE
2828
..\mkdocs.yml = ..\mkdocs.yml
29+
NuGet.config = NuGet.config
2930
..\README.md = ..\README.md
3031
EndProjectSection
3132
EndProject

src/GitVersionCore/BuildServers/AppVeyor.cs

+110-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
using System;
44
using System.Net;
55
using System.Text;
6+
#if !NETDESKTOP
7+
using System.Net.Http;
8+
using System.Threading.Tasks;
9+
using System.Net.Http.Headers;
10+
using Newtonsoft.Json;
11+
using System.IO;
12+
#endif
613

714
public class AppVeyor : BuildServerBase
815
{
@@ -13,6 +20,97 @@ public override bool CanApplyToCurrentContext()
1320
return !string.IsNullOrEmpty(Environment.GetEnvironmentVariable(EnvironmentVariableName));
1421
}
1522

23+
#if !NETDESKTOP
24+
25+
26+
public override string GenerateSetVersionMessage(VersionVariables variables)
27+
{
28+
29+
var buildNumber = Environment.GetEnvironmentVariable("APPVEYOR_BUILD_NUMBER");
30+
var restBase = Environment.GetEnvironmentVariable("APPVEYOR_API_URL");
31+
32+
var request = (HttpWebRequest)WebRequest.Create(restBase + "api/build");
33+
request.Method = "PUT";
34+
35+
36+
var data = string.Format("{{ \"version\": \"{0}.build.{1}\" }}", variables.FullSemVer, buildNumber);
37+
var bytes = Encoding.UTF8.GetBytes(data);
38+
if (request.Headers == null)
39+
{
40+
request.Headers = new WebHeaderCollection();
41+
}
42+
var bytesLength = bytes.Length;
43+
request.Headers["Content-Length"] = bytesLength.ToString();
44+
45+
// request.ContentLength = bytes.Length;
46+
request.ContentType = "application/json";
47+
48+
using (var writeStream = request.GetRequestStreamAsync().Result)
49+
{
50+
writeStream.Write(bytes, 0, bytes.Length);
51+
}
52+
53+
//var result = request.BeginGetRequestStream((asyncResult) =>
54+
// {
55+
// using (var writeStream = request.EndGetRequestStream(asyncResult))
56+
// {
57+
// writeStream.Write(bytes, 0, bytes.Length);
58+
// }
59+
60+
// }, null);
61+
62+
// result.AsyncWaitHandle.WaitOne(new TimeSpan(0, 3, 0));
63+
64+
using (var response = (HttpWebResponse)request.GetResponseAsync().Result)
65+
{
66+
if (response.StatusCode != HttpStatusCode.OK && response.StatusCode != HttpStatusCode.NoContent)
67+
{
68+
var message = string.Format("Request failed. Received HTTP {0}", response.StatusCode);
69+
return message;
70+
}
71+
}
72+
73+
return string.Format("Set AppVeyor build number to '{0}'.", variables.FullSemVer);
74+
75+
}
76+
77+
78+
public override string[] GenerateSetParameterMessage(string name, string value)
79+
{
80+
81+
// var buildNumber = Environment.GetEnvironmentVariable("APPVEYOR_BUILD_NUMBER");
82+
var restBase = Environment.GetEnvironmentVariable("APPVEYOR_API_URL");
83+
84+
var request = (HttpWebRequest)WebRequest.Create(restBase + "api/build/variables");
85+
request.Method = "POST";
86+
request.ContentType = "application/json";
87+
request.Accept = "application/json";
88+
89+
var data = string.Format("{{ \"name\": \"GitVersion_{0}\", \"value\": \"{1}\" }}", name, value);
90+
var bytes = Encoding.UTF8.GetBytes(data);
91+
if (request.Headers == null)
92+
{
93+
request.Headers = new WebHeaderCollection();
94+
}
95+
var bytesLength = bytes.Length;
96+
// No property for content-length - and no Add() method on header collection? WHAAAAT
97+
// request.ContentLength = bytes.Length;
98+
request.Headers["Content-Length"] = bytesLength.ToString();
99+
100+
using (var writeStream = request.GetRequestStreamAsync().Result)
101+
{
102+
writeStream.Write(bytes, 0, bytes.Length);
103+
}
104+
105+
return new[]
106+
{
107+
string.Format("Adding Environment Variable. name='GitVersion_{0}' value='{1}']", name, value)
108+
};
109+
}
110+
111+
112+
#else
113+
16114
public override string GenerateSetVersionMessage(VersionVariables variables)
17115
{
18116
var buildNumber = Environment.GetEnvironmentVariable("APPVEYOR_BUILD_NUMBER");
@@ -23,7 +121,14 @@ public override string GenerateSetVersionMessage(VersionVariables variables)
23121

24122
var data = string.Format("{{ \"version\": \"{0}.build.{1}\" }}", variables.FullSemVer, buildNumber);
25123
var bytes = Encoding.UTF8.GetBytes(data);
26-
request.ContentLength = bytes.Length;
124+
if (request.Headers == null)
125+
{
126+
request.Headers = new WebHeaderCollection();
127+
}
128+
var bytesLength = bytes.Length;
129+
request.Headers["Content-Length"] = bytesLength.ToString();
130+
131+
// request.ContentLength = bytes.Length;
27132
request.ContentType = "application/json";
28133

29134
using (var writeStream = request.GetRequestStream())
@@ -60,5 +165,9 @@ public override string[] GenerateSetParameterMessage(string name, string value)
60165
string.Format("Adding Environment Variable. name='GitVersion_{0}' value='{1}']", name, value)
61166
};
62167
}
168+
169+
170+
#endif
171+
63172
}
64173
}

src/GitVersionCore/BuildServers/BuildServerList.cs

+2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ public static class BuildServerList
77
{
88
static List<IBuildServer> BuildServers = new List<IBuildServer>
99
{
10+
#if NETDESKTOP
1011
new ContinuaCi(),
12+
#endif
1113
new TeamCity(),
1214
new AppVeyor(),
1315
new MyGet(),

src/GitVersionCore/BuildServers/ContinuaCi.cs

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace GitVersion
22
{
3+
#if NETDESKTOP
34
using Microsoft.Win32;
45

56
public class ContinuaCi : BuildServerBase
@@ -42,4 +43,7 @@ static bool RegistryKeyExists(string keyName, RegistryView registryView)
4243
return localKey != null;
4344
}
4445
}
46+
47+
#endif
48+
4549
}

src/GitVersionCore/BuildServers/MyGet.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public override bool CanApplyToCurrentContext()
1010
var buildRunner = Environment.GetEnvironmentVariable("BuildRunner");
1111

1212
return !string.IsNullOrEmpty(buildRunner)
13-
&& buildRunner.Equals("MyGet", StringComparison.InvariantCultureIgnoreCase);
13+
&& buildRunner.Equals("MyGet", StringComparerUtils.IngoreCaseComparison);
1414
}
1515

1616
public override string[] GenerateSetParameterMessage(string name, string value)
@@ -20,7 +20,7 @@ public override string[] GenerateSetParameterMessage(string name, string value)
2020
string.Format("##myget[setParameter name='GitVersion.{0}' value='{1}']", name, ServiceMessageEscapeHelper.EscapeValue(value))
2121
};
2222

23-
if (string.Equals(name, "LegacySemVerPadded", StringComparison.InvariantCultureIgnoreCase))
23+
if (string.Equals(name, "LegacySemVerPadded", StringComparerUtils.IngoreCaseComparison))
2424
{
2525
messages.Add(string.Format("##myget[buildNumber '{0}']", ServiceMessageEscapeHelper.EscapeValue(value)));
2626
}

src/GitVersionCore/Configuration/Config.cs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.Globalization;
66
using System.Linq;
7+
using System.Reflection;
78
using System.Text.RegularExpressions;
89
using YamlDotNet.Serialization;
910

src/GitVersionCore/Configuration/ConfigurationProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace GitVersion
66
using System.IO;
77
using System.Linq;
88
using System.Text;
9-
using WarningException = System.ComponentModel.WarningException;
9+
using WarningException = GitTools.WarningException;
1010

1111
public class ConfigurationProvider
1212
{

src/GitVersionCore/Configuration/LegacyConfig.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace GitVersion
33
using System.Collections.Generic;
44
using System.Linq;
55
using YamlDotNet.Serialization;
6+
using System.Reflection;
67

78
/// <summary>
89
/// Obsolete properties are added to this, so we can check to see if they are used and provide good error messages for migration
@@ -42,7 +43,9 @@ public Dictionary<string, LegacyBranchConfig> Branches
4243

4344
private T MergeObjects<T>(T target, T source)
4445
{
45-
typeof(T).GetProperties()
46+
47+
var typeInfo = typeof(T);
48+
typeInfo.GetProperties()
4649
.Where(prop => prop.CanRead && prop.CanWrite)
4750
.Select(_ => new
4851
{

src/GitVersionCore/Configuration/OldConfigurationException.cs

+2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ public OldConfigurationException(string message) : base(message)
1010
{
1111
}
1212

13+
#if NETDESKTOP
1314
protected OldConfigurationException(
1415
SerializationInfo info,
1516
StreamingContext context) : base(info, context)
1617
{
1718
}
19+
#endif
1820
}
1921
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Reflection;
4+
5+
//public static class TypeHelper
6+
//{
7+
//#if NETDESKTOP
8+
// public static Type GetType<T>()
9+
// {
10+
// return GetType<T>();
11+
// }
12+
//#else
13+
// public static TypeInfo GetType<T>()
14+
// {
15+
// return GetType<T>();
16+
// }
17+
//#endif
18+
19+
//#if NETDESKTOP
20+
// public static IEnumerable<ConstructorInfo> GetConstructorsForType<T>()
21+
// {
22+
// return GetType<T>().GetConstructors();
23+
// }
24+
//#else
25+
// public static IEnumerable<ConstructorInfo> GetConstructorsForType<T>()
26+
// {
27+
// return GetType<T>().DeclaredConstructors;
28+
// }
29+
//#endif
30+
//}

src/GitVersionCore/ExecuteCore.cs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace GitVersion
22
{
3+
using GitTools;
34
using GitVersion.Helpers;
45
using LibGit2Sharp;
56
using System;

src/GitVersionCore/Extensions/ReadEmbeddedResourceExtensions.cs

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace GitVersionCore.Extensions
22
{
33
using System.IO;
4+
using System.Reflection;
45

56
public static class ReadEmbeddedResourceExtensions
67
{
@@ -23,7 +24,11 @@ public static string ReadAsStringFromEmbeddedResource<T>(this string resourceNam
2324

2425
public static Stream ReadFromEmbeddedResource<T>(this string resourceName)
2526
{
27+
#if NETDESKTOP
2628
var assembly = typeof(T).Assembly;
29+
#else
30+
var assembly = typeof(T).GetTypeInfo().Assembly;
31+
#endif
2732
return assembly.GetManifestResourceStream(resourceName);
2833
}
2934
}

0 commit comments

Comments
 (0)