Skip to content

Commit

Permalink
Add support for .NET Core 2.1 (#985)
Browse files Browse the repository at this point in the history
* Make changes to support .NET Core 2.1 and ASP.NET Core 2.1.
Add ASP.NET Core 2.1 templates.
Updated version to 1.4.0.
  • Loading branch information
Jim Przybylinski authored Jun 13, 2018
1 parent 67cec9c commit bdc463d
Show file tree
Hide file tree
Showing 37 changed files with 776 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@ public class FakeParsedProject : IParsedProject
/// The type of the project.
/// </summary>
public KnownProjectTypes ProjectType { get; set; }

/// <summary>The version of the framework used by the project.</summary>
public string FrameworkVersion { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
<Compile Include="GkeDeployment.cs" />
<Compile Include="GkeDeploymentResult.cs" />
<Compile Include="IParsedProject.cs" />
<Compile Include="IParsedProjectExtensions.cs" />
<Compile Include="IToolsPathProvider.cs" />
<Compile Include="KnownProjectTypes.cs" />
<Compile Include="NetCoreAppUtils.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ public interface IParsedProject
string DirectoryPath { get; }

/// <summary>
/// The type of the project.
/// The type (framework) of the project.
/// </summary>
KnownProjectTypes ProjectType { get; }

/// <summary>The version of the framework used by the project.</summary>
string FrameworkVersion { get; }
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,8 @@ public enum KnownProjectTypes
WebApplication,

/// <summary>
/// An ASP.NET Core 1.0 app
/// An ASP.NET Core app
/// </summary>
NetCoreWebApplication1_0,

/// <summary>
/// An ASP.NET Core 1.1 app
/// </summary>
NetCoreWebApplication1_1,

/// <summary>
/// An ASP.NET Core 2.0 app
/// </summary>
NetCoreWebApplication2_0,
NetCoreWebApplication
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<KnownProjectTypes, string> s_knownRuntimeImages = new Dictionary<KnownProjectTypes, string>
{
[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}";

/// <summary>
/// This template is the smallest possible Dockerfile needed to deploy an ASP.NET Core app to
Expand Down Expand Up @@ -63,12 +56,12 @@ internal static async Task<bool> CreateAppBundleAsync(
IToolsPathProvider pathsProvider,
Action<string> 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<string, string>
{
{ "PATH", $"{Environment.GetEnvironmentVariable("PATH")};{externalTools}" },
{ "PATH", $"{Environment.GetEnvironmentVariable("PATH")};{externalTools}" }
};

Debug.WriteLine($"Using tools from {externalTools}");
Expand All @@ -93,18 +86,18 @@ internal static async Task<bool> CreateAppBundleAsync(
/// <param name="stageDirectory">The directory where to save the Dockerfile.</param>
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))
{
File.Copy(sourceDockerfile, targetDockerfile, overwrite: true);
}
else
{
var content = String.Format(DockerfileDefaultContent, baseImage, entryPointName);
string content = string.Format(DockerfileDefaultContent, baseImage, entryPointName);
File.WriteAllText(targetDockerfile, content);
}
}
Expand All @@ -115,9 +108,9 @@ internal static void CopyOrCreateDockerfile(IParsedProject project, string stage
/// <param name="project">The project.</param>
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);
}

Expand All @@ -128,7 +121,7 @@ internal static void GenerateDockerfile(IParsedProject project)
/// <returns>True if the Dockerfile exists, false otherwise.</returns>
internal static bool CheckDockerfile(IParsedProject project)
{
var targetDockerfile = Path.Combine(project.DirectoryPath, DockerfileName);
string targetDockerfile = Path.Combine(project.DirectoryPath, DockerfileName);
return File.Exists(targetDockerfile);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
using Microsoft.VisualStudio.TemplateWizard;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;

namespace GoogleCloudExtension.TemplateWizards
{
Expand All @@ -41,10 +40,7 @@ public void RunStarted(
{
var provider = (IServiceProvider)automationObject;
var model = (IComponentModel)provider.QueryService<SComponentModel>();
using (var container = new CompositionContainer(model.DefaultExportProvider))
{
container.ComposeParts(this);
}
_wizard = model.DefaultExportProvider.GetExportedValue<T>();
_wizard.RunStarted(automationObject, replacementsDictionary, runKind, customParams);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using EnvDTE;
using GoogleCloudExtension.Deployment;
using System.IO;
using System.Text.RegularExpressions;

namespace GoogleCloudExtension.Projects.DotNet4
{
Expand All @@ -23,6 +24,7 @@ namespace GoogleCloudExtension.Projects.DotNet4
/// </summary>
internal class CsprojProject : IParsedProject
{
private static readonly Regex s_frameworkVersionRegex = new Regex("(?<=Version=v)[\\d.]+");
private readonly Project _project;

#region IParsedProject
Expand All @@ -35,11 +37,16 @@ internal class CsprojProject : IParsedProject

public KnownProjectTypes ProjectType => KnownProjectTypes.WebApplication;

/// <summary>The version of the framework used by the project.</summary>
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

using EnvDTE;
using GoogleCloudExtension.Deployment;
using GoogleCloudExtension.Utils;
using System.IO;
using System.Text.RegularExpressions;

namespace GoogleCloudExtension.Projects.DotNetCore
{
Expand All @@ -24,6 +24,7 @@ namespace GoogleCloudExtension.Projects.DotNetCore
/// </summary>
internal class CsprojProject : IParsedProject
{
private static readonly Regex s_frameworkVersionRegex = new Regex(@"(?<=^netcoreapp)[\d.]+$");
private readonly Project _project;

#region IParsedProject
Expand All @@ -34,34 +35,17 @@ internal class CsprojProject : IParsedProject

public string Name => _project.Name;

public KnownProjectTypes ProjectType { get; }
public KnownProjectTypes ProjectType => KnownProjectTypes.NetCoreWebApplication;

/// <summary>The version of the framework used by the project.</summary>
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>The version of the framework used by the project.</summary>
public string FrameworkVersion { get; } = "1.0.0-preview";

#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using GoogleCloudExtension.Deployment;
using GoogleCloudExtension.PublishDialogSteps.ChoiceStep;
using GoogleCloudExtension.Theming;
using System;

namespace GoogleCloudExtension.PublishDialog
{
Expand Down Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private IEnumerable<Choice> GetChoicesForCurrentProject()
Name = Resources.PublishDialogChoiceStepAppEngineFlexName,
Command = new ProtectedCommand(
OnAppEngineChoiceCommand,
canExecuteCommand: PublishDialog.Project.IsAspNetCoreProject()),
PublishDialog.Project.ProjectType == KnownProjectTypes.NetCoreWebApplication),
Icon = s_appEngineIcon.Value,
ToolTip = Resources.PublishDialogChoiceStepAppEngineToolTip
},
Expand All @@ -109,7 +109,7 @@ private IEnumerable<Choice> GetChoicesForCurrentProject()
Name = Resources.PublishDialogChoiceStepGkeName,
Command = new ProtectedCommand(
OnGkeChoiceCommand,
canExecuteCommand: PublishDialog.Project.IsAspNetCoreProject()),
PublishDialog.Project.ProjectType == KnownProjectTypes.NetCoreWebApplication),
Icon = s_gkeIcon.Value,
ToolTip = Resources.PublishDialogChoiceStepGkeToolTip
},
Expand All @@ -118,7 +118,7 @@ private IEnumerable<Choice> GetChoicesForCurrentProject()
Name = Resources.PublishDialogChoiceStepGceName,
Command = new ProtectedCommand(
OnGceChoiceCommand,
canExecuteCommand: projectType == KnownProjectTypes.WebApplication),
projectType == KnownProjectTypes.WebApplication),
Icon = s_gceIcon.Value,
ToolTip = Resources.PublishDialogChoiceStepGceToolTip
},
Expand Down
Loading

0 comments on commit bdc463d

Please sign in to comment.