Skip to content

Commit 353e495

Browse files
committed
adding support of .NET Standard 2.0 (though it doesn't work properly)
1 parent 27b3c83 commit 353e495

File tree

5 files changed

+20
-16
lines changed

5 files changed

+20
-16
lines changed

src/DataContractJavaScriptConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if !NET35
1+
#if NET45
22

33
using System;
44
using System.Collections.Generic;

src/Heartbeat.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Runtime.Serialization;
33

4-
#if NET35
4+
#if !NET45
55
using Newtonsoft.Json;
66
#endif
77

@@ -11,35 +11,35 @@ namespace WakaTime
1111
public class Heartbeat
1212
{
1313

14-
#if NET35
14+
#if !NET45
1515
[JsonProperty(PropertyName = "entity")]
1616
#else
1717
[DataMember(Name = "entity")]
1818
#endif
1919
public string FileName { get; internal set; }
2020

21-
#if NET35
21+
#if !NET45
2222
[JsonProperty(PropertyName = "timestamp")]
2323
#else
2424
[DataMember(Name = "timestamp")]
2525
#endif
2626
public string Timestamp { get { return ToUnixEpoch(DateTime); } }
2727

28-
#if NET35
28+
#if !NET45
2929
[JsonIgnore]
3030
#else
3131
[IgnoreDataMember]
3232
#endif
3333
public DateTime DateTime { get; internal set; }
3434

35-
#if NET35
35+
#if !NET45
3636
[JsonProperty(PropertyName = "project")]
3737
#else
3838
[DataMember(Name = "project")]
3939
#endif
4040
public string Project { get; internal set; }
4141

42-
#if NET35
42+
#if !NET45
4343
[JsonProperty(PropertyName = "is_write")]
4444
#else
4545
[DataMember(Name = "is_write")]
@@ -63,7 +63,7 @@ private static string ToUnixEpoch(DateTime date)
6363
TimeSpan timestamp = date - epoch;
6464
long seconds = Convert.ToInt64(Math.Floor(timestamp.TotalSeconds));
6565
string milliseconds =
66-
#if NET35
66+
#if !NET45
6767
string.Format("{0:00}:{1:00}:{2:00}",
6868
(int)timestamp.TotalHours,
6969
timestamp.Minutes,

src/PythonManager.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ static bool IsPythonInstalled()
5555

5656
static string GetPathFromMicrosoftRegistry()
5757
{
58+
#if !NETSTANDARD
5859
try
5960
{
6061
var regex = new Regex(@"""([^""]*)\\([^""\\]+(?:\.[^"".\\]+))""");
@@ -87,6 +88,9 @@ static string GetPathFromMicrosoftRegistry()
8788
Logger.Error("GetPathFromMicrosoftRegistry:", ex);
8889
return null;
8990
}
91+
#else
92+
return null;
93+
#endif
9094
}
9195

9296
static string GetPathFromFixedPath()

src/WakaTime.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net35;net45</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.0;net35;net45</TargetFrameworks>
55
<Version>8.0.0</Version>
66
<AssemblyVersion>8.0.0</AssemblyVersion>
77
<FileVersion>8.0.0</FileVersion>
@@ -52,7 +52,7 @@
5252

5353
<ItemGroup>
5454
<PackageReference Include="ini-parser" Version="2.2.4" />
55-
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" Condition="'$(TargetFramework)' == 'net35'" />
55+
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" Condition="'$(TargetFramework)' != 'net45'" />
5656
<PackageReference Include="AsyncBridge.Net35" Version="0.3.1" Condition="'$(TargetFramework)' == 'net35'" />
5757
<PackageReference Include="DotNetZip" Version="1.11.0" Condition="'$(TargetFramework)' == 'net35'" />
5858
<PackageReference Include="TaskParallelLibrary" Version="1.0.2856.0" Condition="'$(TargetFramework)' == 'net35'" />

src/WakaTimeIdePlugin.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
using System.Collections.Concurrent;
88
using System.Threading.Tasks;
99

10-
#if NET35
11-
using Newtonsoft.Json;
12-
#else
10+
#if NET45
1311
using System.Web.Script.Serialization;
12+
#else
13+
using Newtonsoft.Json;
1414
#endif
1515

1616
namespace WakaTime
@@ -296,12 +296,12 @@ private static void ProcessHeartbeats()
296296
string extraHeartbeatsJSON = null;
297297
if (hasExtraHeartbeats)
298298
{
299-
#if NET35
300-
extraHeartbeatsJSON = JsonConvert.SerializeObject(extraHeartbeats, Formatting.None);
301-
#else
299+
#if NET45
302300
var serializer = new JavaScriptSerializer();
303301
serializer.RegisterConverters(new JavaScriptConverter[] { new DataContractJavaScriptConverter(true) });
304302
extraHeartbeatsJSON = serializer.Serialize(extraHeartbeats);
303+
#else
304+
extraHeartbeatsJSON = JsonConvert.SerializeObject(extraHeartbeats, Formatting.None);
305305
#endif
306306
}
307307

0 commit comments

Comments
 (0)