Skip to content
This repository was archived by the owner on May 16, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace GoogleCloudExtension.Deployment
{
/// <summary>
Expand Down Expand Up @@ -45,5 +49,10 @@ public interface IToolsPathProvider
/// Returns the path to Visual Studio Remote Debugger tools.
/// </summary>
string GetRemoteDebuggerToolsPath();

/// <summary>
/// Returns the .NET Core Sdk versions installed on this computer.
/// </summary>
IEnumerable<string> GetNetCoreSdkVersions();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@
<Compile Include="Utils\ProtectedAction.cs" />
<Compile Include="Utils\ToolWindowCommandUtils.cs" />
<Compile Include="VsVersion\VS14\ToolsPathProvider.cs" />
<Compile Include="VsVersion\ToolsPathProviderBase.cs" />
<Compile Include="VsVersion\VS15\ToolsPathProvider.cs" />
<Compile Include="VsVersion\VsVersionUtils.cs" />
<Compile Include="WindowsCredentialsChooser\WindowsCredentialsChooserViewModel.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;

namespace GoogleCloudExtension.TemplateWizards.Dialogs.TemplateChooserDialog
{
Expand Down Expand Up @@ -49,6 +50,9 @@ public class AspNetVersion
/// </summary>
public static readonly AspNetVersion AspNet4 = new AspNetVersion("4", false);

private static readonly Version s_sdkVersion1_0 = new Version(1, 0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Another wrench thrown your way, the latest SDK is actually 1.1.4 and covers both .NET Core runtime 1.0 and 1.1. I think that you are going to have to create a table to codify the releases here, with what versions of .NET Core they target, etc...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment is not accurate, your logic (looking for .NET Core SDK between 1.0.x to 2.0.x) works perfectly.

private static readonly Version s_sdkVersion2_0 = new Version(2, 0);

/// <summary>
/// The version number of ASP.NET. This corresponds to the version of .NET Core used as well.
/// </summary>
Expand All @@ -59,6 +63,12 @@ public class AspNetVersion
/// </summary>
private bool IsCore { get; }

/// <summary>
/// Gets the installed .NET Core SDK versions.
/// </summary>
private static IEnumerable<string> NetCoreSdkVersions =>
VsVersionUtils.ToolsPathProvider.GetNetCoreSdkVersions();

[JsonConstructor]
private AspNetVersion(string version, bool isCore = true)
{
Expand All @@ -71,23 +81,48 @@ private AspNetVersion(string version, bool isCore = true)
/// </summary>
private static IList<AspNetVersion> GetVs2015AspNetCoreVersions()
{
return new List<AspNetVersion>
if (NetCoreSdkVersions.Any(sdkVersion => sdkVersion.StartsWith("1.0.0-preview")))
{
AspNetCore1Preview
};
return new List<AspNetVersion>
{
AspNetCore1Preview
};
}
else
{
return new List<AspNetVersion>();
}
}

/// <summary>
/// ASP.NET Core versions available to VS 2017.
/// </summary>
private static IList<AspNetVersion> GetVs2017AspNetCoreVersions()
{
return new List<AspNetVersion>
List<Version> sdkVersions = GetParsedSdkVersions().ToList();
var aspNetVersions = new List<AspNetVersion>();
if (sdkVersions.Any(version => version >= s_sdkVersion1_0 && version < s_sdkVersion2_0))
{
AspNetCore10,
AspNetCore11,
AspNetCore20
};
aspNetVersions.Add(AspNetCore10);
aspNetVersions.Add(AspNetCore11);
}
if (sdkVersions.Any(version => version >= s_sdkVersion2_0))
{
aspNetVersions.Add(AspNetCore20);
}
return aspNetVersions;
}

private static IEnumerable<Version> GetParsedSdkVersions()
{
foreach (string sdkVersion in NetCoreSdkVersions)
{
Version result;
if (System.Version.TryParse(sdkVersion, out result))
{
yield return result;
}
}
}

/// <summary>
Expand All @@ -103,24 +138,21 @@ public override string ToString()
/// <summary>
/// Gets the versions available for specified version of Visual Studio and Framework type.
/// </summary>
/// <param name="vsVersion">The string visual studio version.</param>
/// <param name="framework">The <see cref="FrameworkType"/> that will run this template.</param>
/// <returns>A new list of AspNetVersions from which are compatible with the vsVersion and framework.</returns>
public static IList<AspNetVersion> GetAvailableVersions(string vsVersion, FrameworkType framework)
public static IList<AspNetVersion> GetAvailableVersions(FrameworkType framework)
{
switch (framework)
{
case FrameworkType.NetFramework:
return new List<AspNetVersion> {AspNet4};
return new List<AspNetVersion> { AspNet4 };
case FrameworkType.NetCore:
switch (vsVersion)
switch (GoogleCloudExtensionPackage.VsVersion)
{
case VsVersionUtils.VisualStudio2015Version:
return GetVs2015AspNetCoreVersions();
// ReSharper disable once RedundantCaseLabel
case VsVersionUtils.VisualStudio2017Version:
// For forward compatibility, give future versions of VS the same options as VS2017.
default:
// For forward compatibility, give future versions of VS the same options as VS2017.
return GetVs2017AspNetCoreVersions();
}
case FrameworkType.None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public FrameworkType SelectedFramework
set
{
SetValueAndRaise(ref _selectedFramework, value);
AvailableVersions = AspNetVersion.GetAvailableVersions(
GoogleCloudExtensionPackage.VsVersion, SelectedFramework);
AvailableVersions = AspNetVersion.GetAvailableVersions(SelectedFramework);
}
}

Expand Down Expand Up @@ -146,6 +145,10 @@ private set
/// </summary>
public TemplateChooserViewModelResult Result { get; private set; }

public bool NetCoreAvailable { get; } = IsNetCoreAvailable();

private static bool IsNetCoreAvailable() => AspNetVersion.GetAvailableVersions(FrameworkType.NetCore).Any();

/// <param name="closeWindow">The action that will close the dialog.</param>
/// <param name="promptPickProject">The function that will prompt the user to pick an existing project.</param>
public TemplateChooserViewModel(Action closeWindow, Func<string> promptPickProject)
Expand All @@ -159,7 +162,7 @@ public TemplateChooserViewModel(Action closeWindow, Func<string> promptPickProje
},
false);
SelectProjectCommand = new ProtectedCommand(() => GcpProjectId = promptPickProject() ?? GcpProjectId);
SelectedFramework = FrameworkType.NetCore;
SelectedFramework = NetCoreAvailable ? FrameworkType.NetCore : FrameworkType.NetFramework;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@

<ComboBoxItem
Tag="{x:Static local:FrameworkType.NetCore}"
Content="{x:Static ext:Resources.FrameworkTypeDisplayNameNetCore}"/>
Content="{x:Static ext:Resources.FrameworkTypeDisplayNameNetCore}"
Visibility="{Binding NetCoreAvailable, Converter={utils:VisibilityConverter}}"
/>
<ComboBoxItem
Tag="{x:Static local:FrameworkType.NetFramework}"
Content="{x:Static ext:Resources.FrameworkTypeDisplayNameNetFramework}"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using GoogleCloudExtension.Deployment;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace GoogleCloudExtension.VsVersion
{
internal abstract class ToolsPathProviderBase : IToolsPathProvider
{
internal const string SdkDirectoryName = "sdk";
internal const string NugetFallbackFolderName = "NuGetFallbackFolder";

/// <inheritdoc />
public abstract string GetExternalToolsPath();

/// <inheritdoc />
public abstract string GetDotnetPath();

/// <inheritdoc />
public abstract string GetMsbuildPath();

/// <inheritdoc />
public abstract string GetMsdeployPath();

/// <inheritdoc />
public abstract string GetRemoteDebuggerToolsPath();

/// <inheritdoc />
public IEnumerable<string> GetNetCoreSdkVersions()
{
string dotnetDir = Path.GetDirectoryName(GetDotnetPath());
if (dotnetDir == null)
{
return Enumerable.Empty<string>();
}
string sdkDirectoryPath = Path.Combine(dotnetDir, SdkDirectoryName);
if (!Directory.Exists(sdkDirectoryPath))
{
return Enumerable.Empty<string>();
}
Version dummy;
return Directory.EnumerateDirectories(sdkDirectoryPath)
.Select(Path.GetFileName)
.Where(
sdkVersion =>
sdkVersion.StartsWith("1.0.0-preview") || Version.TryParse(sdkVersion, out dummy));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,50 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using GoogleCloudExtension.Deployment;
using GoogleCloudExtension.Utils;
using System;
using System.IO;

namespace GoogleCloudExtension.VsVersion.VS14
{
/// <summary>
/// The implementation of <seealso cref="IToolsPathProvider"/> for Visual Studio 2015 (v14.0).
/// The implementation of <seealso cref="Deployment.IToolsPathProvider"/> for Visual Studio 2015 (v14.0).
/// </summary>
internal class ToolsPathProvider : IToolsPathProvider
internal class ToolsPathProvider : ToolsPathProviderBase
{
public string GetExternalToolsPath()
public override string GetExternalToolsPath()
{
var programFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
var result = Path.Combine(programFilesPath, @"Microsoft Visual Studio 14.0\Web\External");
GcpOutputWindow.OutputDebugLine($"External tools path: {result}");
return result;
}

public string GetDotnetPath()
public override string GetDotnetPath()
{
var programFilesPath = Environment.ExpandEnvironmentVariables("%ProgramW6432%");
var result = Path.Combine(programFilesPath, @"dotnet\dotnet.exe");
GcpOutputWindow.OutputDebugLine($"Dotnet path: {result}");
return result;
}

public string GetMsbuildPath()
public override string GetMsbuildPath()
{
var programFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
var result = Path.Combine(programFilesPath, @"MSBuild\14.0\Bin\MSBuild.exe");
GcpOutputWindow.OutputDebugLine($"Msbuild path: {result}");
return result;
}

public string GetMsdeployPath()
public override string GetMsdeployPath()
{
var programFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
var result = Path.Combine(programFilesPath, @"IIS\Microsoft Web Deploy V3\msdeploy.exe");
GcpOutputWindow.OutputDebugLine($"Msdeploy path: {result}");
return result;
}

public string GetRemoteDebuggerToolsPath()
public override string GetRemoteDebuggerToolsPath()
{
var programFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
// TODO: add x86 support later
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
using GoogleCloudExtension.Deployment;
using GoogleCloudExtension.Utils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace GoogleCloudExtension.VsVersion.VS15
{
/// <summary>
/// The implementation of <seealso cref="IToolsPathProvider"/> for Visual Studio 2017 (v 15.0).
/// </summary>
internal class ToolsPathProvider : IToolsPathProvider
internal class ToolsPathProvider : ToolsPathProviderBase
{
private readonly string _edition;

Expand All @@ -31,23 +33,23 @@ public ToolsPathProvider(string edition)
_edition = edition;
}

public string GetDotnetPath()
public override string GetDotnetPath()
{
var programFilesPath = Environment.ExpandEnvironmentVariables("%ProgramW6432%");
var result = Path.Combine(programFilesPath, @"dotnet\dotnet.exe");
GcpOutputWindow.OutputDebugLine($"Dotnet path: {result}");
return result;
}

public string GetExternalToolsPath()
public override string GetExternalToolsPath()
{
var programFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
var result = Path.Combine(programFilesPath, $@"Microsoft Visual Studio\2017\{_edition}\Web\External");
GcpOutputWindow.OutputDebugLine($"External tools path: {result}");
return result;
}

public string GetMsbuildPath()
public override string GetMsbuildPath()
{
var programFilesPath = Environment.GetEnvironmentVariable("ProgramFiles(x86)");
var result = Path.Combine(programFilesPath, $@"Microsoft Visual Studio\2017\{_edition}\MSBuild\15.0\Bin\MSBuild.exe");
Expand All @@ -56,7 +58,7 @@ public string GetMsbuildPath()
return result;
}

public string GetMsdeployPath()
public override string GetMsdeployPath()
{
var programFilesPath = Environment.GetEnvironmentVariable("ProgramFiles");
var result = Path.Combine(programFilesPath, @"IIS\Microsoft Web Deploy V3\msdeploy.exe");
Expand All @@ -65,7 +67,7 @@ public string GetMsdeployPath()
return result;
}

public string GetRemoteDebuggerToolsPath()
public override string GetRemoteDebuggerToolsPath()
{
var programFilesPath = Environment.GetEnvironmentVariable("ProgramFiles(x86)");
// TODO: add x86 support later
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ internal static class VsVersionUtils
public const string VisualStudio2015Version = "14.0";
public const string VisualStudio2017Version = "15.0";

private static readonly Lazy<IToolsPathProvider> s_toolsPathProvider = new Lazy<IToolsPathProvider>(GetTooslPathProvider);
internal static Lazy<IToolsPathProvider> s_toolsPathProvider =
new Lazy<IToolsPathProvider>(GetTooslPathProvider);
private static readonly Lazy<int> s_remoteDebuggerPort = new Lazy<int>(GetRemoteDebuggerPort);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,17 @@
<Compile Include="Utils\Validation\StringValidationResultTests.cs" />
<Compile Include="Utils\Validation\ValidatingViewModelBaseTests.cs" />
<Compile Include="TemplateWizards\Dialogs\PickProjectIdViewModelTests.cs" />
<Compile Include="VsVersion\ToolsPathProviderBaseTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GoogleCloudExtension.DataSources\GoogleCloudExtension.DataSources.csproj">
<Project>{3988AAC1-3B20-4BA1-9627-ED7D3C80145F}</Project>
<Name>GoogleCloudExtension.DataSources</Name>
</ProjectReference>
<ProjectReference Include="..\GoogleCloudExtension.Deployment\GoogleCloudExtension.Deployment.csproj">
<Project>{92c6e0d0-41d8-4ecc-87e1-ae72fca891fc}</Project>
<Name>GoogleCloudExtension.Deployment</Name>
</ProjectReference>
<ProjectReference Include="..\GoogleCloudExtension.Interop\GoogleCloudExtension.Interop.csproj">
<Project>{856b9f2e-441f-405a-9d5c-af5dc5653902}</Project>
<Name>GoogleCloudExtension.Interop</Name>
Expand Down
Loading