Skip to content
This repository was archived by the owner on May 16, 2025. It is now read-only.

Commit bdc463d

Browse files
author
Jim Przybylinski
authored
Add support for .NET Core 2.1 (#985)
* 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.
1 parent 67cec9c commit bdc463d

File tree

37 files changed

+776
-214
lines changed

37 files changed

+776
-214
lines changed

GoogleCloudExtension/GoogleCloudExtension.Deployment.UnitTests/FakeParsedProject.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,8 @@ public class FakeParsedProject : IParsedProject
3535
/// The type of the project.
3636
/// </summary>
3737
public KnownProjectTypes ProjectType { get; set; }
38+
39+
/// <summary>The version of the framework used by the project.</summary>
40+
public string FrameworkVersion { get; set; }
3841
}
3942
}

GoogleCloudExtension/GoogleCloudExtension.Deployment/GoogleCloudExtension.Deployment.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@
9494
<Compile Include="GkeDeployment.cs" />
9595
<Compile Include="GkeDeploymentResult.cs" />
9696
<Compile Include="IParsedProject.cs" />
97-
<Compile Include="IParsedProjectExtensions.cs" />
9897
<Compile Include="IToolsPathProvider.cs" />
9998
<Compile Include="KnownProjectTypes.cs" />
10099
<Compile Include="NetCoreAppUtils.cs" />

GoogleCloudExtension/GoogleCloudExtension.Deployment/IParsedProject.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ public interface IParsedProject
3232
string DirectoryPath { get; }
3333

3434
/// <summary>
35-
/// The type of the project.
35+
/// The type (framework) of the project.
3636
/// </summary>
3737
KnownProjectTypes ProjectType { get; }
38+
39+
/// <summary>The version of the framework used by the project.</summary>
40+
string FrameworkVersion { get; }
3841
}
3942
}

GoogleCloudExtension/GoogleCloudExtension.Deployment/IParsedProjectExtensions.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.

GoogleCloudExtension/GoogleCloudExtension.Deployment/KnownProjectTypes.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,8 @@ public enum KnownProjectTypes
3030
WebApplication,
3131

3232
/// <summary>
33-
/// An ASP.NET Core 1.0 app
33+
/// An ASP.NET Core app
3434
/// </summary>
35-
NetCoreWebApplication1_0,
36-
37-
/// <summary>
38-
/// An ASP.NET Core 1.1 app
39-
/// </summary>
40-
NetCoreWebApplication1_1,
41-
42-
/// <summary>
43-
/// An ASP.NET Core 2.0 app
44-
/// </summary>
45-
NetCoreWebApplication2_0,
35+
NetCoreWebApplication
4636
}
4737
}

GoogleCloudExtension/GoogleCloudExtension.Deployment/NetCoreAppUtils.cs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,7 @@ namespace GoogleCloudExtension.Deployment
2828
internal static class NetCoreAppUtils
2929
{
3030
internal const string DockerfileName = "Dockerfile";
31-
32-
// The mapping of supported .NET Core versions to the base images to use for the Docker image.
33-
private static readonly Dictionary<KnownProjectTypes, string> s_knownRuntimeImages = new Dictionary<KnownProjectTypes, string>
34-
{
35-
[KnownProjectTypes.NetCoreWebApplication1_0] = "gcr.io/google-appengine/aspnetcore:1.0",
36-
[KnownProjectTypes.NetCoreWebApplication1_1] = "gcr.io/google-appengine/aspnetcore:1.1",
37-
[KnownProjectTypes.NetCoreWebApplication2_0] = "gcr.io/google-appengine/aspnetcore:2.0"
38-
};
31+
private const string RuntimeImageFormat = "gcr.io/google-appengine/aspnetcore:{0}";
3932

4033
/// <summary>
4134
/// This template is the smallest possible Dockerfile needed to deploy an ASP.NET Core app to
@@ -63,12 +56,12 @@ internal static async Task<bool> CreateAppBundleAsync(
6356
IToolsPathProvider pathsProvider,
6457
Action<string> outputAction)
6558
{
66-
var arguments = $"publish -o \"{stageDirectory}\" -c Release";
67-
var externalTools = pathsProvider.GetExternalToolsPath();
68-
var workingDir = project.DirectoryPath;
59+
string arguments = $"publish -o \"{stageDirectory}\" -c Release";
60+
string externalTools = pathsProvider.GetExternalToolsPath();
61+
string workingDir = project.DirectoryPath;
6962
var env = new Dictionary<string, string>
7063
{
71-
{ "PATH", $"{Environment.GetEnvironmentVariable("PATH")};{externalTools}" },
64+
{ "PATH", $"{Environment.GetEnvironmentVariable("PATH")};{externalTools}" }
7265
};
7366

7467
Debug.WriteLine($"Using tools from {externalTools}");
@@ -93,18 +86,18 @@ internal static async Task<bool> CreateAppBundleAsync(
9386
/// <param name="stageDirectory">The directory where to save the Dockerfile.</param>
9487
internal static void CopyOrCreateDockerfile(IParsedProject project, string stageDirectory)
9588
{
96-
var sourceDockerfile = Path.Combine(project.DirectoryPath, DockerfileName);
97-
var targetDockerfile = Path.Combine(stageDirectory, DockerfileName);
98-
var entryPointName = CommonUtils.GetEntrypointName(stageDirectory) ?? project.Name;
99-
var baseImage = s_knownRuntimeImages[project.ProjectType];
89+
string sourceDockerfile = Path.Combine(project.DirectoryPath, DockerfileName);
90+
string targetDockerfile = Path.Combine(stageDirectory, DockerfileName);
91+
string entryPointName = CommonUtils.GetEntrypointName(stageDirectory) ?? project.Name;
92+
string baseImage = string.Format(RuntimeImageFormat, project.FrameworkVersion);
10093

10194
if (File.Exists(sourceDockerfile))
10295
{
10396
File.Copy(sourceDockerfile, targetDockerfile, overwrite: true);
10497
}
10598
else
10699
{
107-
var content = String.Format(DockerfileDefaultContent, baseImage, entryPointName);
100+
string content = string.Format(DockerfileDefaultContent, baseImage, entryPointName);
108101
File.WriteAllText(targetDockerfile, content);
109102
}
110103
}
@@ -115,9 +108,9 @@ internal static void CopyOrCreateDockerfile(IParsedProject project, string stage
115108
/// <param name="project">The project.</param>
116109
internal static void GenerateDockerfile(IParsedProject project)
117110
{
118-
var targetDockerfile = Path.Combine(project.DirectoryPath, DockerfileName);
119-
var baseImage = s_knownRuntimeImages[project.ProjectType];
120-
var content = String.Format(DockerfileDefaultContent, baseImage, project.Name);
111+
string targetDockerfile = Path.Combine(project.DirectoryPath, DockerfileName);
112+
string baseImage = string.Format(RuntimeImageFormat, project.FrameworkVersion);
113+
string content = string.Format(DockerfileDefaultContent, baseImage, project.Name);
121114
File.WriteAllText(targetDockerfile, content);
122115
}
123116

@@ -128,7 +121,7 @@ internal static void GenerateDockerfile(IParsedProject project)
128121
/// <returns>True if the Dockerfile exists, false otherwise.</returns>
129122
internal static bool CheckDockerfile(IParsedProject project)
130123
{
131-
var targetDockerfile = Path.Combine(project.DirectoryPath, DockerfileName);
124+
string targetDockerfile = Path.Combine(project.DirectoryPath, DockerfileName);
132125
return File.Exists(targetDockerfile);
133126
}
134127
}

GoogleCloudExtension/GoogleCloudExtension.TemplateWizards/DelegatingTemplateWizard.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
using Microsoft.VisualStudio.TemplateWizard;
2020
using System.Collections.Generic;
2121
using System.ComponentModel.Composition;
22-
using System.ComponentModel.Composition.Hosting;
2322

2423
namespace GoogleCloudExtension.TemplateWizards
2524
{
@@ -41,10 +40,7 @@ public void RunStarted(
4140
{
4241
var provider = (IServiceProvider)automationObject;
4342
var model = (IComponentModel)provider.QueryService<SComponentModel>();
44-
using (var container = new CompositionContainer(model.DefaultExportProvider))
45-
{
46-
container.ComposeParts(this);
47-
}
43+
_wizard = model.DefaultExportProvider.GetExportedValue<T>();
4844
_wizard.RunStarted(automationObject, replacementsDictionary, runKind, customParams);
4945
}
5046

GoogleCloudExtension/GoogleCloudExtension/GenerateConfigurationCommand/GenerateConfigurationContextMenuCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ private void OnBeforeQueryStatus(object sender, EventArgs e)
160160
}
161161

162162
// Ensure that the menu entry is only available for ASP.NET Core projects.
163-
var selectedProject = SolutionHelper.CurrentSolution.SelectedProject?.ParsedProject;
164-
if (selectedProject == null || !selectedProject.IsAspNetCoreProject())
163+
IParsedProject selectedProject = SolutionHelper.CurrentSolution.SelectedProject?.ParsedProject;
164+
if (selectedProject?.ProjectType != KnownProjectTypes.NetCoreWebApplication)
165165
{
166166
menuCommand.Visible = false;
167167
}

GoogleCloudExtension/GoogleCloudExtension/Projects/DotNet4/CsprojProject.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using EnvDTE;
1616
using GoogleCloudExtension.Deployment;
1717
using System.IO;
18+
using System.Text.RegularExpressions;
1819

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

2830
#region IParsedProject
@@ -35,11 +37,16 @@ internal class CsprojProject : IParsedProject
3537

3638
public KnownProjectTypes ProjectType => KnownProjectTypes.WebApplication;
3739

40+
/// <summary>The version of the framework used by the project.</summary>
41+
public string FrameworkVersion { get; }
42+
3843
#endregion
3944

4045
public CsprojProject(Project project)
4146
{
4247
_project = project;
48+
string targetFramework = project.Properties.Item("TargetFrameworkMoniker").Value.ToString();
49+
FrameworkVersion = s_frameworkVersionRegex.Match(targetFramework).Value;
4350
}
4451
}
4552
}

GoogleCloudExtension/GoogleCloudExtension/Projects/DotNetCore/CsprojProject.cs

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
using EnvDTE;
1616
using GoogleCloudExtension.Deployment;
17-
using GoogleCloudExtension.Utils;
1817
using System.IO;
18+
using System.Text.RegularExpressions;
1919

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

2930
#region IParsedProject
@@ -34,34 +35,17 @@ internal class CsprojProject : IParsedProject
3435

3536
public string Name => _project.Name;
3637

37-
public KnownProjectTypes ProjectType { get; }
38+
public KnownProjectTypes ProjectType => KnownProjectTypes.NetCoreWebApplication;
39+
40+
/// <summary>The version of the framework used by the project.</summary>
41+
public string FrameworkVersion { get; }
3842

3943
#endregion
4044

4145
public CsprojProject(Project project, string targetFramework)
4246
{
43-
GcpOutputWindow.OutputDebugLine($"Found project {project.FullName} targeting {targetFramework}");
44-
4547
_project = project;
46-
switch (targetFramework)
47-
{
48-
case "netcoreapp1.0":
49-
ProjectType = KnownProjectTypes.NetCoreWebApplication1_0;
50-
break;
51-
52-
case "netcoreapp1.1":
53-
ProjectType = KnownProjectTypes.NetCoreWebApplication1_1;
54-
break;
55-
56-
case "netcoreapp2.0":
57-
ProjectType = KnownProjectTypes.NetCoreWebApplication2_0;
58-
break;
59-
60-
default:
61-
GcpOutputWindow.OutputDebugLine($"Unsopported target framework {targetFramework}");
62-
ProjectType = KnownProjectTypes.None;
63-
break;
64-
}
48+
FrameworkVersion = s_frameworkVersionRegex.Match(targetFramework).Value;
6549
}
6650
}
6751
}

0 commit comments

Comments
 (0)