Skip to content

Commit d24e303

Browse files
committed
Enable multi-targeting to NetFX 4.6.1 on Windows
Enable building the class libraries and head CLI project against .NET Framework 4.6.1 when compiling on Windows. This enables the Windows-only authentication helpers (which build against the Microsoft.Git.CredentialManager.dll library) to avoid pulling in the .NET Standard type-forwarding libraries, which not only allows us to deploy the helpers and the main GCM executable in to the same directory without conflicting type-fwd libraries, but also greatly reduces the number of assemblies required to ship on Windows.
1 parent 603541d commit d24e303

File tree

5 files changed

+43
-3
lines changed

5 files changed

+43
-3
lines changed

common/src/Git-Credential-Manager/Git-Credential-Manager.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>netcoreapp2.1</TargetFramework>
6+
<TargetFramework Condition="'$(OS)'!='Unix'">net461</TargetFramework>
67
<RuntimeIdentifiers>win-x64;osx-x64</RuntimeIdentifiers>
78
<AssemblyName>git-credential-manager</AssemblyName>
89
<RootNamespace>Microsoft.Git.CredentialManager</RootNamespace>
@@ -16,4 +17,8 @@
1617
<ProjectReference Include="..\Microsoft.Git.CredentialManager\Microsoft.Git.CredentialManager.csproj" />
1718
</ItemGroup>
1819

20+
<ItemGroup Condition="'$(TargetFramework)'=='net461'">
21+
<ProjectReference Include="..\..\..\windows\src\Microsoft.Authentication.Helper\Microsoft.Authentication.Helper.csproj" />
22+
</ItemGroup>
23+
1924
</Project>

common/src/GitHub/GitHub.csproj

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

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
4+
<TargetFrameworks>netstandard2.0</TargetFrameworks>
5+
<TargetFrameworks Condition="'$(OS)'!='Unix'">netstandard2.0;net461</TargetFrameworks>
56
<RootNamespace>GitHub</RootNamespace>
67
<AssemblyName>GitHub</AssemblyName>
78
<IsTestProject>false</IsTestProject>
@@ -12,4 +13,8 @@
1213
<ProjectReference Include="..\Microsoft.Git.CredentialManager\Microsoft.Git.CredentialManager.csproj" />
1314
</ItemGroup>
1415

16+
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
17+
<Reference Include="System.Net.Http" />
18+
</ItemGroup>
19+
1520
</Project>

common/src/Microsoft.AzureRepos/Microsoft.AzureRepos.csproj

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

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
4+
<TargetFrameworks>netstandard2.0</TargetFrameworks>
5+
<TargetFrameworks Condition="'$(OS)'!='Unix'">netstandard2.0;net461</TargetFrameworks>
56
<IsTestProject>false</IsTestProject>
67
<LangVersion>latest</LangVersion>
78
<RootNamespace>Microsoft.AzureRepos</RootNamespace>
@@ -12,4 +13,8 @@
1213
<ProjectReference Include="..\Microsoft.Git.CredentialManager\Microsoft.Git.CredentialManager.csproj" />
1314
</ItemGroup>
1415

16+
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
17+
<Reference Include="System.Net.Http" />
18+
</ItemGroup>
19+
1520
</Project>
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
4+
<TargetFrameworks>netstandard2.0</TargetFrameworks>
5+
<TargetFrameworks Condition="'$(OS)'!='Unix'">netstandard2.0;net461</TargetFrameworks>
56
<IsTestProject>false</IsTestProject>
67
<LangVersion>latest</LangVersion>
78
<RootNamespace>Microsoft.Git.CredentialManager</RootNamespace>
89
<AssemblyName>Microsoft.Git.CredentialManager</AssemblyName>
910
</PropertyGroup>
1011

12+
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
13+
<Reference Include="System.Net.Http" />
14+
</ItemGroup>
15+
1116
</Project>

common/src/Microsoft.Git.CredentialManager/PlatformUtils.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ public static PlatformInformation GetPlatformInformation()
2626
/// <returns>True if running on macOS, false otherwise.</returns>
2727
public static bool IsMacOS()
2828
{
29+
#if NETFRAMEWORK
30+
return Environment.OSVersion.Platform == PlatformID.MacOSX;
31+
#elif NETSTANDARD
2932
return RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
33+
#endif
3034
}
3135

3236
/// <summary>
@@ -35,7 +39,11 @@ public static bool IsMacOS()
3539
/// <returns>True if running on Windows, false otherwise.</returns>
3640
public static bool IsWindows()
3741
{
42+
#if NETFRAMEWORK
43+
return Environment.OSVersion.Platform == PlatformID.Win32NT;
44+
#elif NETSTANDARD
3845
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
46+
#endif
3947
}
4048

4149
/// <summary>
@@ -44,7 +52,11 @@ public static bool IsWindows()
4452
/// <returns>True if running on a Linux distribution, false otherwise.</returns>
4553
public static bool IsLinux()
4654
{
55+
#if NETFRAMEWORK
56+
return Environment.OSVersion.Platform == PlatformID.Unix;
57+
#elif NETSTANDARD
4758
return RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
59+
#endif
4860
}
4961

5062
/// <summary>
@@ -107,6 +119,9 @@ private static string GetOSType()
107119

108120
private static string GetCpuArchitecture()
109121
{
122+
#if NETFRAMEWORK
123+
return Environment.Is64BitOperatingSystem ? "x86-64" : "x86";
124+
#elif NETSTANDARD
110125
switch (RuntimeInformation.OSArchitecture)
111126
{
112127
case Architecture.Arm:
@@ -120,11 +135,16 @@ private static string GetCpuArchitecture()
120135
default:
121136
return RuntimeInformation.OSArchitecture.ToString();
122137
}
138+
#endif
123139
}
124140

125141
private static string GetClrVersion()
126142
{
143+
#if NETFRAMEWORK
144+
return $".NET Framework {Environment.Version}";
145+
#elif NETSTANDARD
127146
return RuntimeInformation.FrameworkDescription;
147+
#endif
128148
}
129149

130150
#endregion

0 commit comments

Comments
 (0)