diff --git a/GoogleCloudExtension/GoogleCloudExtension.Deployment.UnitTests/FakeParsedProject.cs b/GoogleCloudExtension/GoogleCloudExtension.Deployment.UnitTests/FakeParsedProject.cs
index 844f84bdf..a95909b87 100644
--- a/GoogleCloudExtension/GoogleCloudExtension.Deployment.UnitTests/FakeParsedProject.cs
+++ b/GoogleCloudExtension/GoogleCloudExtension.Deployment.UnitTests/FakeParsedProject.cs
@@ -35,5 +35,8 @@ public class FakeParsedProject : IParsedProject
/// The type of the project.
///
public KnownProjectTypes ProjectType { get; set; }
+
+ /// The version of the framework used by the project.
+ public string FrameworkVersion { get; set; }
}
}
diff --git a/GoogleCloudExtension/GoogleCloudExtension.Deployment/GoogleCloudExtension.Deployment.csproj b/GoogleCloudExtension/GoogleCloudExtension.Deployment/GoogleCloudExtension.Deployment.csproj
index 766770a34..482794533 100644
--- a/GoogleCloudExtension/GoogleCloudExtension.Deployment/GoogleCloudExtension.Deployment.csproj
+++ b/GoogleCloudExtension/GoogleCloudExtension.Deployment/GoogleCloudExtension.Deployment.csproj
@@ -94,7 +94,6 @@
-
diff --git a/GoogleCloudExtension/GoogleCloudExtension.Deployment/IParsedProject.cs b/GoogleCloudExtension/GoogleCloudExtension.Deployment/IParsedProject.cs
index 932b6fcce..0102144d6 100644
--- a/GoogleCloudExtension/GoogleCloudExtension.Deployment/IParsedProject.cs
+++ b/GoogleCloudExtension/GoogleCloudExtension.Deployment/IParsedProject.cs
@@ -32,8 +32,11 @@ public interface IParsedProject
string DirectoryPath { get; }
///
- /// The type of the project.
+ /// The type (framework) of the project.
///
KnownProjectTypes ProjectType { get; }
+
+ /// The version of the framework used by the project.
+ string FrameworkVersion { get; }
}
}
diff --git a/GoogleCloudExtension/GoogleCloudExtension.Deployment/IParsedProjectExtensions.cs b/GoogleCloudExtension/GoogleCloudExtension.Deployment/IParsedProjectExtensions.cs
deleted file mode 100644
index f4a169b0b..000000000
--- a/GoogleCloudExtension/GoogleCloudExtension.Deployment/IParsedProjectExtensions.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2017 Google Inc. All Rights Reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-
-namespace GoogleCloudExtension.Deployment
-{
- ///
- /// Useful checks for projects.
- ///
- public static class IParsedProjectExtensions
- {
- ///
- /// Determines if the given project is a .NET Core project or not.
- ///
- /// The project to check.
- /// Returns true if the project is a .NET Core project, false otherwise.
- public static bool IsAspNetCoreProject(this IParsedProject project)
- => project.ProjectType == KnownProjectTypes.NetCoreWebApplication1_0 ||
- project.ProjectType == KnownProjectTypes.NetCoreWebApplication1_1 ||
- project.ProjectType == KnownProjectTypes.NetCoreWebApplication2_0;
- }
-}
diff --git a/GoogleCloudExtension/GoogleCloudExtension.Deployment/KnownProjectTypes.cs b/GoogleCloudExtension/GoogleCloudExtension.Deployment/KnownProjectTypes.cs
index 8a2169b3c..079f45399 100644
--- a/GoogleCloudExtension/GoogleCloudExtension.Deployment/KnownProjectTypes.cs
+++ b/GoogleCloudExtension/GoogleCloudExtension.Deployment/KnownProjectTypes.cs
@@ -30,18 +30,8 @@ public enum KnownProjectTypes
WebApplication,
///
- /// An ASP.NET Core 1.0 app
+ /// An ASP.NET Core app
///
- NetCoreWebApplication1_0,
-
- ///
- /// An ASP.NET Core 1.1 app
- ///
- NetCoreWebApplication1_1,
-
- ///
- /// An ASP.NET Core 2.0 app
- ///
- NetCoreWebApplication2_0,
+ NetCoreWebApplication
}
}
\ No newline at end of file
diff --git a/GoogleCloudExtension/GoogleCloudExtension.Deployment/NetCoreAppUtils.cs b/GoogleCloudExtension/GoogleCloudExtension.Deployment/NetCoreAppUtils.cs
index 23a8a3ed6..5e465dfa6 100644
--- a/GoogleCloudExtension/GoogleCloudExtension.Deployment/NetCoreAppUtils.cs
+++ b/GoogleCloudExtension/GoogleCloudExtension.Deployment/NetCoreAppUtils.cs
@@ -28,14 +28,7 @@ namespace GoogleCloudExtension.Deployment
internal static class NetCoreAppUtils
{
internal const string DockerfileName = "Dockerfile";
-
- // The mapping of supported .NET Core versions to the base images to use for the Docker image.
- private static readonly Dictionary s_knownRuntimeImages = new Dictionary
- {
- [KnownProjectTypes.NetCoreWebApplication1_0] = "gcr.io/google-appengine/aspnetcore:1.0",
- [KnownProjectTypes.NetCoreWebApplication1_1] = "gcr.io/google-appengine/aspnetcore:1.1",
- [KnownProjectTypes.NetCoreWebApplication2_0] = "gcr.io/google-appengine/aspnetcore:2.0"
- };
+ private const string RuntimeImageFormat = "gcr.io/google-appengine/aspnetcore:{0}";
///
/// This template is the smallest possible Dockerfile needed to deploy an ASP.NET Core app to
@@ -63,12 +56,12 @@ internal static async Task CreateAppBundleAsync(
IToolsPathProvider pathsProvider,
Action outputAction)
{
- var arguments = $"publish -o \"{stageDirectory}\" -c Release";
- var externalTools = pathsProvider.GetExternalToolsPath();
- var workingDir = project.DirectoryPath;
+ string arguments = $"publish -o \"{stageDirectory}\" -c Release";
+ string externalTools = pathsProvider.GetExternalToolsPath();
+ string workingDir = project.DirectoryPath;
var env = new Dictionary
{
- { "PATH", $"{Environment.GetEnvironmentVariable("PATH")};{externalTools}" },
+ { "PATH", $"{Environment.GetEnvironmentVariable("PATH")};{externalTools}" }
};
Debug.WriteLine($"Using tools from {externalTools}");
@@ -93,10 +86,10 @@ internal static async Task CreateAppBundleAsync(
/// The directory where to save the Dockerfile.
internal static void CopyOrCreateDockerfile(IParsedProject project, string stageDirectory)
{
- var sourceDockerfile = Path.Combine(project.DirectoryPath, DockerfileName);
- var targetDockerfile = Path.Combine(stageDirectory, DockerfileName);
- var entryPointName = CommonUtils.GetEntrypointName(stageDirectory) ?? project.Name;
- var baseImage = s_knownRuntimeImages[project.ProjectType];
+ string sourceDockerfile = Path.Combine(project.DirectoryPath, DockerfileName);
+ string targetDockerfile = Path.Combine(stageDirectory, DockerfileName);
+ string entryPointName = CommonUtils.GetEntrypointName(stageDirectory) ?? project.Name;
+ string baseImage = string.Format(RuntimeImageFormat, project.FrameworkVersion);
if (File.Exists(sourceDockerfile))
{
@@ -104,7 +97,7 @@ internal static void CopyOrCreateDockerfile(IParsedProject project, string stage
}
else
{
- var content = String.Format(DockerfileDefaultContent, baseImage, entryPointName);
+ string content = string.Format(DockerfileDefaultContent, baseImage, entryPointName);
File.WriteAllText(targetDockerfile, content);
}
}
@@ -115,9 +108,9 @@ internal static void CopyOrCreateDockerfile(IParsedProject project, string stage
/// The project.
internal static void GenerateDockerfile(IParsedProject project)
{
- var targetDockerfile = Path.Combine(project.DirectoryPath, DockerfileName);
- var baseImage = s_knownRuntimeImages[project.ProjectType];
- var content = String.Format(DockerfileDefaultContent, baseImage, project.Name);
+ string targetDockerfile = Path.Combine(project.DirectoryPath, DockerfileName);
+ string baseImage = string.Format(RuntimeImageFormat, project.FrameworkVersion);
+ string content = string.Format(DockerfileDefaultContent, baseImage, project.Name);
File.WriteAllText(targetDockerfile, content);
}
@@ -128,7 +121,7 @@ internal static void GenerateDockerfile(IParsedProject project)
/// True if the Dockerfile exists, false otherwise.
internal static bool CheckDockerfile(IParsedProject project)
{
- var targetDockerfile = Path.Combine(project.DirectoryPath, DockerfileName);
+ string targetDockerfile = Path.Combine(project.DirectoryPath, DockerfileName);
return File.Exists(targetDockerfile);
}
}
diff --git a/GoogleCloudExtension/GoogleCloudExtension.TemplateWizards/DelegatingTemplateWizard.cs b/GoogleCloudExtension/GoogleCloudExtension.TemplateWizards/DelegatingTemplateWizard.cs
index 73ea4297d..53cfa4d00 100644
--- a/GoogleCloudExtension/GoogleCloudExtension.TemplateWizards/DelegatingTemplateWizard.cs
+++ b/GoogleCloudExtension/GoogleCloudExtension.TemplateWizards/DelegatingTemplateWizard.cs
@@ -19,7 +19,6 @@
using Microsoft.VisualStudio.TemplateWizard;
using System.Collections.Generic;
using System.ComponentModel.Composition;
-using System.ComponentModel.Composition.Hosting;
namespace GoogleCloudExtension.TemplateWizards
{
@@ -41,10 +40,7 @@ public void RunStarted(
{
var provider = (IServiceProvider)automationObject;
var model = (IComponentModel)provider.QueryService();
- using (var container = new CompositionContainer(model.DefaultExportProvider))
- {
- container.ComposeParts(this);
- }
+ _wizard = model.DefaultExportProvider.GetExportedValue();
_wizard.RunStarted(automationObject, replacementsDictionary, runKind, customParams);
}
diff --git a/GoogleCloudExtension/GoogleCloudExtension/GenerateConfigurationCommand/GenerateConfigurationContextMenuCommand.cs b/GoogleCloudExtension/GoogleCloudExtension/GenerateConfigurationCommand/GenerateConfigurationContextMenuCommand.cs
index 56ac950d5..81f31e4cf 100644
--- a/GoogleCloudExtension/GoogleCloudExtension/GenerateConfigurationCommand/GenerateConfigurationContextMenuCommand.cs
+++ b/GoogleCloudExtension/GoogleCloudExtension/GenerateConfigurationCommand/GenerateConfigurationContextMenuCommand.cs
@@ -160,8 +160,8 @@ private void OnBeforeQueryStatus(object sender, EventArgs e)
}
// Ensure that the menu entry is only available for ASP.NET Core projects.
- var selectedProject = SolutionHelper.CurrentSolution.SelectedProject?.ParsedProject;
- if (selectedProject == null || !selectedProject.IsAspNetCoreProject())
+ IParsedProject selectedProject = SolutionHelper.CurrentSolution.SelectedProject?.ParsedProject;
+ if (selectedProject?.ProjectType != KnownProjectTypes.NetCoreWebApplication)
{
menuCommand.Visible = false;
}
diff --git a/GoogleCloudExtension/GoogleCloudExtension/Projects/DotNet4/CsprojProject.cs b/GoogleCloudExtension/GoogleCloudExtension/Projects/DotNet4/CsprojProject.cs
index 51d5ce6fa..c6e51c284 100644
--- a/GoogleCloudExtension/GoogleCloudExtension/Projects/DotNet4/CsprojProject.cs
+++ b/GoogleCloudExtension/GoogleCloudExtension/Projects/DotNet4/CsprojProject.cs
@@ -15,6 +15,7 @@
using EnvDTE;
using GoogleCloudExtension.Deployment;
using System.IO;
+using System.Text.RegularExpressions;
namespace GoogleCloudExtension.Projects.DotNet4
{
@@ -23,6 +24,7 @@ namespace GoogleCloudExtension.Projects.DotNet4
///
internal class CsprojProject : IParsedProject
{
+ private static readonly Regex s_frameworkVersionRegex = new Regex("(?<=Version=v)[\\d.]+");
private readonly Project _project;
#region IParsedProject
@@ -35,11 +37,16 @@ internal class CsprojProject : IParsedProject
public KnownProjectTypes ProjectType => KnownProjectTypes.WebApplication;
+ /// The version of the framework used by the project.
+ public string FrameworkVersion { get; }
+
#endregion
public CsprojProject(Project project)
{
_project = project;
+ string targetFramework = project.Properties.Item("TargetFrameworkMoniker").Value.ToString();
+ FrameworkVersion = s_frameworkVersionRegex.Match(targetFramework).Value;
}
}
}
\ No newline at end of file
diff --git a/GoogleCloudExtension/GoogleCloudExtension/Projects/DotNetCore/CsprojProject.cs b/GoogleCloudExtension/GoogleCloudExtension/Projects/DotNetCore/CsprojProject.cs
index 0ee63c8ec..956762e66 100644
--- a/GoogleCloudExtension/GoogleCloudExtension/Projects/DotNetCore/CsprojProject.cs
+++ b/GoogleCloudExtension/GoogleCloudExtension/Projects/DotNetCore/CsprojProject.cs
@@ -14,8 +14,8 @@
using EnvDTE;
using GoogleCloudExtension.Deployment;
-using GoogleCloudExtension.Utils;
using System.IO;
+using System.Text.RegularExpressions;
namespace GoogleCloudExtension.Projects.DotNetCore
{
@@ -24,6 +24,7 @@ namespace GoogleCloudExtension.Projects.DotNetCore
///
internal class CsprojProject : IParsedProject
{
+ private static readonly Regex s_frameworkVersionRegex = new Regex(@"(?<=^netcoreapp)[\d.]+$");
private readonly Project _project;
#region IParsedProject
@@ -34,34 +35,17 @@ internal class CsprojProject : IParsedProject
public string Name => _project.Name;
- public KnownProjectTypes ProjectType { get; }
+ public KnownProjectTypes ProjectType => KnownProjectTypes.NetCoreWebApplication;
+
+ /// The version of the framework used by the project.
+ public string FrameworkVersion { get; }
#endregion
public CsprojProject(Project project, string targetFramework)
{
- GcpOutputWindow.OutputDebugLine($"Found project {project.FullName} targeting {targetFramework}");
-
_project = project;
- switch (targetFramework)
- {
- case "netcoreapp1.0":
- ProjectType = KnownProjectTypes.NetCoreWebApplication1_0;
- break;
-
- case "netcoreapp1.1":
- ProjectType = KnownProjectTypes.NetCoreWebApplication1_1;
- break;
-
- case "netcoreapp2.0":
- ProjectType = KnownProjectTypes.NetCoreWebApplication2_0;
- break;
-
- default:
- GcpOutputWindow.OutputDebugLine($"Unsopported target framework {targetFramework}");
- ProjectType = KnownProjectTypes.None;
- break;
- }
+ FrameworkVersion = s_frameworkVersionRegex.Match(targetFramework).Value;
}
}
}
diff --git a/GoogleCloudExtension/GoogleCloudExtension/Projects/DotNetCore/JsonProject.cs b/GoogleCloudExtension/GoogleCloudExtension/Projects/DotNetCore/JsonProject.cs
index 1e5c00cd6..d3fe15b6d 100644
--- a/GoogleCloudExtension/GoogleCloudExtension/Projects/DotNetCore/JsonProject.cs
+++ b/GoogleCloudExtension/GoogleCloudExtension/Projects/DotNetCore/JsonProject.cs
@@ -32,7 +32,10 @@ internal class JsonProject : IParsedProject
public string Name => Path.GetFileName(Path.GetDirectoryName(_projectJsonPath));
- public KnownProjectTypes ProjectType => KnownProjectTypes.NetCoreWebApplication1_0;
+ public KnownProjectTypes ProjectType => KnownProjectTypes.NetCoreWebApplication;
+
+ /// The version of the framework used by the project.
+ public string FrameworkVersion { get; } = "1.0.0-preview";
#endregion
diff --git a/GoogleCloudExtension/GoogleCloudExtension/Properties/AssemblyInfo.cs b/GoogleCloudExtension/GoogleCloudExtension/Properties/AssemblyInfo.cs
index 3f6d64039..d6de050f2 100644
--- a/GoogleCloudExtension/GoogleCloudExtension/Properties/AssemblyInfo.cs
+++ b/GoogleCloudExtension/GoogleCloudExtension/Properties/AssemblyInfo.cs
@@ -35,8 +35,8 @@
// This version number matches the version in the .vsixmanifest. Please update both versions at the
// same time.
-[assembly: AssemblyVersion("1.3.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
+[assembly: AssemblyVersion("1.4.0.0")]
+[assembly: AssemblyFileVersion("1.4.0.0")]
[assembly: InternalsVisibleTo(
"GoogleCloudExtensionUnitTests," +
"PublicKey=0024000004800000940000000602000000240000525341310004000001000" +
diff --git a/GoogleCloudExtension/GoogleCloudExtension/PublishDialog/PublishDialogWindow.cs b/GoogleCloudExtension/GoogleCloudExtension/PublishDialog/PublishDialogWindow.cs
index 553867fba..eaea7d10b 100644
--- a/GoogleCloudExtension/GoogleCloudExtension/PublishDialog/PublishDialogWindow.cs
+++ b/GoogleCloudExtension/GoogleCloudExtension/PublishDialog/PublishDialogWindow.cs
@@ -15,7 +15,6 @@
using GoogleCloudExtension.Deployment;
using GoogleCloudExtension.PublishDialogSteps.ChoiceStep;
using GoogleCloudExtension.Theming;
-using System;
namespace GoogleCloudExtension.PublishDialog
{
@@ -54,9 +53,7 @@ public static bool CanPublish(IParsedProject project)
{
var projectType = project.ProjectType;
return projectType == KnownProjectTypes.WebApplication ||
- projectType == KnownProjectTypes.NetCoreWebApplication1_0 ||
- projectType == KnownProjectTypes.NetCoreWebApplication1_1 ||
- projectType == KnownProjectTypes.NetCoreWebApplication2_0;
+ projectType == KnownProjectTypes.NetCoreWebApplication;
}
}
}
diff --git a/GoogleCloudExtension/GoogleCloudExtension/PublishDialogSteps/ChoiceStep/ChoiceStepViewModel.cs b/GoogleCloudExtension/GoogleCloudExtension/PublishDialogSteps/ChoiceStep/ChoiceStepViewModel.cs
index 6514e4a87..74e13d2c7 100644
--- a/GoogleCloudExtension/GoogleCloudExtension/PublishDialogSteps/ChoiceStep/ChoiceStepViewModel.cs
+++ b/GoogleCloudExtension/GoogleCloudExtension/PublishDialogSteps/ChoiceStep/ChoiceStepViewModel.cs
@@ -100,7 +100,7 @@ private IEnumerable GetChoicesForCurrentProject()
Name = Resources.PublishDialogChoiceStepAppEngineFlexName,
Command = new ProtectedCommand(
OnAppEngineChoiceCommand,
- canExecuteCommand: PublishDialog.Project.IsAspNetCoreProject()),
+ PublishDialog.Project.ProjectType == KnownProjectTypes.NetCoreWebApplication),
Icon = s_appEngineIcon.Value,
ToolTip = Resources.PublishDialogChoiceStepAppEngineToolTip
},
@@ -109,7 +109,7 @@ private IEnumerable GetChoicesForCurrentProject()
Name = Resources.PublishDialogChoiceStepGkeName,
Command = new ProtectedCommand(
OnGkeChoiceCommand,
- canExecuteCommand: PublishDialog.Project.IsAspNetCoreProject()),
+ PublishDialog.Project.ProjectType == KnownProjectTypes.NetCoreWebApplication),
Icon = s_gkeIcon.Value,
ToolTip = Resources.PublishDialogChoiceStepGkeToolTip
},
@@ -118,7 +118,7 @@ private IEnumerable GetChoicesForCurrentProject()
Name = Resources.PublishDialogChoiceStepGceName,
Command = new ProtectedCommand(
OnGceChoiceCommand,
- canExecuteCommand: projectType == KnownProjectTypes.WebApplication),
+ projectType == KnownProjectTypes.WebApplication),
Icon = s_gceIcon.Value,
ToolTip = Resources.PublishDialogChoiceStepGceToolTip
},
diff --git a/GoogleCloudExtension/GoogleCloudExtension/TemplateWizards/Dialogs/TemplateChooserDialog/AspNetVersion.cs b/GoogleCloudExtension/GoogleCloudExtension/TemplateWizards/Dialogs/TemplateChooserDialog/AspNetVersion.cs
index 7096087bf..fa3b4eb91 100644
--- a/GoogleCloudExtension/GoogleCloudExtension/TemplateWizards/Dialogs/TemplateChooserDialog/AspNetVersion.cs
+++ b/GoogleCloudExtension/GoogleCloudExtension/TemplateWizards/Dialogs/TemplateChooserDialog/AspNetVersion.cs
@@ -45,13 +45,19 @@ public class AspNetVersion
///
public static readonly AspNetVersion AspNetCore20 = new AspNetVersion("2.0");
+ ///
+ /// ASP.NET Core 2.1.
+ ///
+ public static readonly AspNetVersion AspNetCore21 = new AspNetVersion("2.1");
+
///
/// ASP.NET 4.
///
public static readonly AspNetVersion AspNet4 = new AspNetVersion("4", false);
- private static readonly Version s_sdkVersion1_0 = new Version(1, 0);
- private static readonly Version s_sdkVersion2_0 = new Version(2, 0);
+ // Find these values at https://www.microsoft.com/net/download/all
+ internal static readonly Version s_firstSdkVersionWith11Runtime = new Version(1, 1, 4);
+ internal static readonly Version s_firstSdkVersionWith21Runtime = new Version(2, 1, 300);
///
/// The version number of ASP.NET. This corresponds to the version of .NET Core used as well.
@@ -99,19 +105,30 @@ private static IList GetVs2015AspNetCoreVersions()
///
private static IList GetVs2017AspNetCoreVersions()
{
- List sdkVersions = GetParsedSdkVersions().ToList();
+ ILookup sdkVersions = GetParsedSdkVersions().ToLookup(v => v.Major);
+ List majorVersion1Versions = sdkVersions[1].ToList();
+ List majorVersion2Versions = sdkVersions[2].ToList();
var aspNetVersions = new List();
- if (sdkVersions.Any(version => version >= s_sdkVersion1_0 && version < s_sdkVersion2_0))
+ if (majorVersion1Versions.Count > 0)
{
aspNetVersions.Add(AspNetCore10);
+ }
+
+ if (majorVersion1Versions.Any(version => version >= s_firstSdkVersionWith11Runtime))
+ {
aspNetVersions.Add(AspNetCore11);
}
- if (sdkVersions.Any(version => version >= s_sdkVersion2_0))
+ if (majorVersion2Versions.Count > 0)
{
aspNetVersions.Add(AspNetCore20);
}
+ if (majorVersion2Versions.Any(version => version >= s_firstSdkVersionWith21Runtime))
+ {
+ aspNetVersions.Add(AspNetCore21);
+ }
+
return aspNetVersions;
}
diff --git a/GoogleCloudExtension/GoogleCloudExtension/TemplateWizards/GoogleProjectTemplateSelectorWizard.cs b/GoogleCloudExtension/GoogleCloudExtension/TemplateWizards/GoogleProjectTemplateSelectorWizard.cs
index ddd625b7f..bdb55170e 100644
--- a/GoogleCloudExtension/GoogleCloudExtension/TemplateWizards/GoogleProjectTemplateSelectorWizard.cs
+++ b/GoogleCloudExtension/GoogleCloudExtension/TemplateWizards/GoogleProjectTemplateSelectorWizard.cs
@@ -26,7 +26,7 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
-using System.Text.RegularExpressions;
+using System.Xml.Linq;
using IServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
namespace GoogleCloudExtension.TemplateWizards
@@ -37,10 +37,10 @@ namespace GoogleCloudExtension.TemplateWizards
[Export(typeof(IGoogleProjectTemplateSelectorWizard))]
public class GoogleProjectTemplateSelectorWizard : IGoogleProjectTemplateSelectorWizard
{
- // Find the AspNet or AspNetCore part of c:\path\to\template\Gcp.AspNet.vstemplate
- private static readonly Regex s_templateTypeRegex = new Regex(@"(?<=Gcp\.)[^.]*(?=\.vstemplate$)");
// Mockable static methods for unit testing.
- internal Func PromptUser = TemplateChooserWindow.PromptUser;
+ internal Func PromptUser =
+ TemplateChooserWindow.PromptUser;
+
internal Action> CleanupDirectories = GoogleTemplateWizardHelper.CleanupDirectories;
///
@@ -64,7 +64,7 @@ public void RunStarted(
}
else
{
- TemplateType templateType = GetTemplateTypeFromPath(thisTemplatePath);
+ TemplateType templateType = GetTemplateTypeFromWizardData(replacements);
result = PromptUser(projectName, templateType);
}
if (result == null)
@@ -73,7 +73,7 @@ public void RunStarted(
}
string thisTemplateDirectory =
- Path.GetFullPath(Path.Combine(thisTemplatePath, "..", "..", "..", ".."));
+ Path.GetFullPath(Path.Combine(thisTemplatePath, "..", "..", "..", ".."));
var serviceProvider = automationObject as IServiceProvider;
@@ -97,52 +97,57 @@ public void RunStarted(
CleanupDirectories(replacements);
throw;
}
+
// Delegated wizard created the solution. Cancel repeated creation of the solution.
throw new WizardCancelledException();
}
- private TemplateType GetTemplateTypeFromPath(string thisTemplatePath)
+ private TemplateType GetTemplateTypeFromWizardData(IReadOnlyDictionary replacements)
{
- string templateTypeName = s_templateTypeRegex.Match(thisTemplatePath).Value;
- TemplateType result;
- if (Enum.TryParse(templateTypeName, out result))
- {
- return result;
- }
- else
+ string wizardDataXml;
+ if (replacements.TryGetValue(ReplacementsKeys.WizardDataKey, out wizardDataXml))
{
- return TemplateType.AspNetCore;
+ XElement wizardData = XElement.Parse(wizardDataXml);
+ string templateTypeName = wizardData.DescendantsAndSelf()
+ .SingleOrDefault(n => n.Name.LocalName == "TemplateType")?.Value;
+ TemplateType result;
+ if (Enum.TryParse(templateTypeName, out result))
+ {
+ return result;
+ }
}
+
+ return TemplateType.AspNetCore;
}
///
public void ProjectFinishedGenerating(Project project)
{
- throw new NotImplementedException("This wizard should delegate to another template and cancel itself.");
+ throw new NotSupportedException("This wizard should delegate to another template and cancel itself.");
}
///
public void ProjectItemFinishedGenerating(ProjectItem projectItem)
{
- throw new NotImplementedException("This wizard should delegate to another template and cancel itself.");
+ throw new NotSupportedException("This wizard should delegate to another template and cancel itself.");
}
///
public bool ShouldAddProjectItem(string filePath)
{
- throw new NotImplementedException("This wizard should delegate to another template and cancel itself.");
+ throw new NotSupportedException("This wizard should delegate to another template and cancel itself.");
}
///
public void BeforeOpeningFile(ProjectItem projectItem)
{
- throw new NotImplementedException("This wizard should delegate to another template and cancel itself.");
+ throw new NotSupportedException("This wizard should delegate to another template and cancel itself.");
}
///
public void RunFinished()
{
- throw new NotImplementedException("This wizard should delegate to another wizard and cancel itself.");
+ throw new NotSupportedException("This wizard should delegate to another wizard and cancel itself.");
}
private static object[] GetNewCustomParams(
@@ -183,6 +188,7 @@ private static object[] GetNewCustomParams(
$"Invalid {nameof(FrameworkType)}: {result.SelectedFramework}");
}
}
+
return customParams.Cast().Concat(additionalCustomParams).ToArray