Skip to content

Commit

Permalink
Constrain EF Core 8 / .NET 8 projects to VS 17.8
Browse files Browse the repository at this point in the history
fixes #1981
  • Loading branch information
ErikEJ committed Oct 26, 2023
1 parent 5ffa5a3 commit f33e408
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/GUI/EFCorePowerTools/EFCorePowerToolsPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ internal TView GetView<TView>()
return extensionServices.GetService<TView>();
}

internal async Task<Version> VisualStudioVersionAsync()
{
return await VS.Shell.GetVsVersionAsync();
}

protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
try
Expand Down Expand Up @@ -292,11 +297,6 @@ private static bool IsConfigFile(string itemName)
itemName.EndsWith(".config.json", StringComparison.OrdinalIgnoreCase);
}

private async Task<Version> VisualStudioVersionAsync()
{
return await VS.Shell.GetVsVersionAsync();
}

#pragma warning disable VSTHRD100 // Avoid async void methods
private async void OnReverseEngineerConfigFileMenuBeforeQueryStatus(object sender, EventArgs e)
#pragma warning restore VSTHRD100 // Avoid async void methods
Expand Down
2 changes: 1 addition & 1 deletion src/GUI/Shared/DAL/DotNetAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace EFCorePowerTools.DAL
{
public class DotNetAccess : IDotNetAccess
{
string IDotNetAccess.GetExtensionVersion() => FileVersionInfo.GetVersionInfo(typeof(EFCorePowerToolsPackage)?.Assembly.Location).FileVersion ?? null;
string IDotNetAccess.GetExtensionVersion() => FileVersionInfo.GetVersionInfo(typeof(EFCorePowerToolsPackage).Assembly.Location).FileVersion ?? null;
}
}
2 changes: 2 additions & 0 deletions src/GUI/Shared/DAL/VisualStudioAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ DatabaseConnectionModel IVisualStudioAccess.PromptForNewDatabaseConnection()
info = await VsDataHelper.PromptForInfoAsync();
});

#pragma warning disable S2583 // Conditionally executed code should be reachable
if (info == null)
{
return null;
}
#pragma warning restore S2583 // Conditionally executed code should be reachable

if (info.DatabaseType == DatabaseType.Undefined)
{
Expand Down
2 changes: 2 additions & 0 deletions src/GUI/Shared/Extensions/ProjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ public static List<string> GetConfigFiles(this Project project)
result.AddRange(files
.Where(f => !f.Contains("\\bin\\") && !f.Contains("\\obj\\")));

#pragma warning disable S2583 // Conditionally executed code should be reachable
if (result.Count == 0)
{
result.Add(Path.Combine(projectPath, "efpt.config.json"));
}
#pragma warning restore S2583 // Conditionally executed code should be reachable

return result.OrderBy(s => s).ToList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,15 @@ private async Task<bool> ChooseDataBaseConnectionAsync(ReverseEngineerOptions op
psd.PublishSchemas(options.Schemas);
}

var (usedMode, allowedVersions) = reverseEngineerHelper.CalculateAllowedVersions(options.CodeGenerationMode, await project.GetEFCoreVersionHintAsync());
var vsVersion = await package.VisualStudioVersionAsync();

var (usedMode, allowedVersions) = reverseEngineerHelper.CalculateAllowedVersions(options.CodeGenerationMode, await project.GetEFCoreVersionHintAsync(), vsVersion);

if (!allowedVersions.Any())
{
VSHelper.ShowError($".NET 5 and earlier is not supported, and EF Core 8 requires Visual Studio 17.8 or later");
return false;
}

psd.PublishCodeGenerationMode(usedMode, allowedVersions);

Expand Down
6 changes: 3 additions & 3 deletions src/GUI/Shared/Helpers/ReverseEngineerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public string DropTemplates(string optionsPath, string projectPath, CodeGenerati
return string.Empty;
}

public (CodeGenerationMode UsedMode, IList<CodeGenerationItem> AllowedVersions) CalculateAllowedVersions(CodeGenerationMode codeGenerationMode, Version minimumVersion)
public (CodeGenerationMode UsedMode, IList<CodeGenerationItem> AllowedVersions) CalculateAllowedVersions(CodeGenerationMode codeGenerationMode, Version minimumVersion, Version vsVersion)
{
var list = new List<CodeGenerationItem>();

Expand All @@ -136,14 +136,14 @@ public string DropTemplates(string optionsPath, string projectPath, CodeGenerati
list.Add(new CodeGenerationItem { Key = (int)CodeGenerationMode.EFCore6, Value = "EF Core 6" });
}

if (minimumVersion.Major == 8)
if (minimumVersion.Major == 8 && vsVersion >= new Version(17, 8))
{
list.Add(new CodeGenerationItem { Key = (int)CodeGenerationMode.EFCore8, Value = "EF Core 8 (preview)" });
}

if (!list.Any())
{
throw new InvalidOperationException(".NET 5 and earlier projects are no longer supported");
return (codeGenerationMode, list);
}

var firstMode = list.Select(i => i.Key).First();
Expand Down

0 comments on commit f33e408

Please sign in to comment.