Skip to content

Commit

Permalink
6.0.7 servicing (#1943)
Browse files Browse the repository at this point in the history
* not packaging other runtimes in CG.Design (#1912)

* added support for sqlite for minimal api scaffolding. (#1915)

* fix nullable warnings for new db context template. (#1916)

* fixed identity Program.cs changes (#1940)

* fix Program.cs changes for identity scenario.

* added some comments.

* bumped up version.
  • Loading branch information
deepchoudhery authored Jun 28, 2022
1 parent 7f121ff commit e58fc93
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 89 deletions.
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<!-- Ref packages -->
</PropertyGroup>
<PropertyGroup>
<VersionPrefix>6.0.6</VersionPrefix>
<VersionPrefix>6.0.7</VersionPrefix>
<PreReleaseVersionLabel>rtm</PreReleaseVersionLabel>
<IsServicingBuild Condition="'$(PreReleaseVersionLabel)' == 'servicing'">true</IsServicingBuild>
<!--
Expand Down
23 changes: 0 additions & 23 deletions src/Scaffolding/VS.Web.CG.Design/VS.Web.CG.Design.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@
<TargetFramework>net6.0</TargetFramework>
<PackageTags>aspnetcore;codegenerator;scaffolding;visualstudioweb</PackageTags>
<PackageId>Microsoft.VisualStudio.Web.CodeGeneration.Design</PackageId>
<X86BinDirectory>$(ArtifactsBinDir)VS.Web.CG.Design-x86\</X86BinDirectory>
<ARMBinDirectory>$(ArtifactsBinDir)VS.Web.CG.Design-arm\</ARMBinDirectory>
<ARM64BinDirectory>$(ArtifactsBinDir)VS.Web.CG.Design-arm64\</ARM64BinDirectory>
<AnyCpuBinDirectory>$(ArtifactsBinDir)VS.Web.CG.Design-anycpu\</AnyCpuBinDirectory>

<X86ProjectDirectory>$(RepoRoot)src\Scaffolding\VS.Web.CG.Design-x86\</X86ProjectDirectory>
<ARMProjectDirectory>$(RepoRoot)src\Scaffolding\VS.Web.CG.Design-arm\</ARMProjectDirectory>
<ARM64ProjectDirectory>$(RepoRoot)src\Scaffolding\VS.Web.CG.Design-arm64\</ARM64ProjectDirectory>
<AnyCpuProjectDirectory>$(RepoRoot)src\Scaffolding\VS.Web.CG.Design-anycpu\</AnyCpuProjectDirectory>
<IncludeBuildOutput>false</IncludeBuildOutput>
</PropertyGroup>

Expand All @@ -32,19 +23,5 @@
<Pack>true</Pack>
<PackagePath>lib\net6.0\</PackagePath>
</Content>

<Content Include="$(ARMBinDirectory)$(Configuration)\net6.0\win-arm\$(AssemblyName).exe;
$(ARMBinDirectory)$(Configuration)\net6.0\win-arm\$(AssemblyName).xml;"
Condition=" '$(DotNetBuildFromSource)' != 'true' ">
<Pack>true</Pack>
<PackagePath>runtimes\win-arm\lib\net6.0\</PackagePath>
</Content>

<Content Include="$(ARM64BinDirectory)$(Configuration)\net6.0\win-arm64\$(AssemblyName).exe;
$(ARM64BinDirectory)$(Configuration)\net6.0\win-arm64\$(AssemblyName).xml;"
Condition=" '$(DotNetBuildFromSource)' != 'true' ">
<Pack>true</Pack>
<PackagePath>runtimes\win-arm64\lib\net6.0\</PackagePath>
</Content>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ using Microsoft.EntityFrameworkCore;
{
}

public DbSet<@Model.ModelTypeFullName>? @Model.ModelTypeName { get; set; }
public DbSet<@Model.ModelTypeFullName> @Model.ModelTypeName { get; set; } = default!;
}
@{
if (!String.IsNullOrEmpty(Model.DbContextNamespace))
Expand Down
63 changes: 9 additions & 54 deletions src/Scaffolding/VS.Web.CG.Mvc/Identity/IdentityGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,60 +170,15 @@ public IdentityGenerator(IApplicationInfo applicationInfo,
IFileSystem fileSystem,
ILogger logger)
{
if (applicationInfo == null)
{
throw new ArgumentNullException(nameof(applicationInfo));
}

if (serviceProvider == null)
{
throw new ArgumentNullException(nameof(serviceProvider));
}

if (actionService == null)
{
throw new ArgumentNullException(nameof(actionService));
}

if (projectContext == null)
{
throw new ArgumentNullException(nameof(projectContext));
}

if (connectionStringsWriter == null)
{
throw new ArgumentNullException(nameof(connectionStringsWriter));
}

if (workspace == null)
{
throw new ArgumentNullException(nameof(workspace));
}

if (loader == null)
{
throw new ArgumentNullException(nameof(loader));
}

if (fileSystem == null)
{
throw new ArgumentNullException(nameof(fileSystem));
}

if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

_applicationInfo = applicationInfo;
_serviceProvider = serviceProvider;
_codegeneratorActionService = actionService;
_projectContext = projectContext;
_connectionStringsWriter = connectionStringsWriter;
_workspace = workspace;
_loader = loader;
_fileSystem = fileSystem;
_logger = logger;
_applicationInfo = applicationInfo ?? throw new ArgumentNullException(nameof(applicationInfo));
_serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
_codegeneratorActionService = actionService ?? throw new ArgumentNullException(nameof(actionService));
_projectContext = projectContext ?? throw new ArgumentNullException(nameof(projectContext));
_connectionStringsWriter = connectionStringsWriter ?? throw new ArgumentNullException(nameof(connectionStringsWriter));
_workspace = workspace ?? throw new ArgumentNullException(nameof(workspace));
_loader = loader ?? throw new ArgumentNullException(nameof(loader));
_fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}

public async Task GenerateCode(IdentityGeneratorCommandLineModel commandlineModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -705,11 +705,10 @@ private async Task<Type> FindExistingType(string type)
Environment.NewLine,
string.Join(Environment.NewLine, _reflectedTypesProvider.GetCompilationErrors())));
}

}

var reflectedType = _reflectedTypesProvider.GetReflectedType(type, true);

return reflectedType;
//get all types and return the one with the same name. There should be no duplicates so only one should match.
return _reflectedTypesProvider.GetAllTypesInProject().FirstOrDefault(r => r.Name.Equals(type, StringComparison.OrdinalIgnoreCase));
}

private void ValidateCommandLine(IdentityGeneratorCommandLineModel model)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
},
{
"InsertAfter": "builder.Configuration.GetConnectionString",
"Block": "builder.Services.AddDbContext<{0}>(options =>\r\n{1}options.{0}(connectionString));\"",
"CheckBlock": "builder.Services.AddDbContext",
"Block": "builder.Services.AddDbContext<{0}>(options =>\r\n{1}options.{0}(connectionString))\"",
"LeadingTrivia": {
"Newline": true
}
},
{
"InsertAfter": "builder.Services.AddDbContext",
"CheckBlock": "builder.Services.AddDefaultIdentity",
"Block": "builder.Services.AddDefaultIdentity<{0}>(options => options.SignIn.RequireConfirmedAccount = true)\r\n{1}.AddEntityFrameworkStores<{0}>();\"",
"Block": "builder.Services.AddDefaultIdentity<{0}>(options => options.SignIn.RequireConfirmedAccount = true)\r\n{1}.AddEntityFrameworkStores<{0}>()\"",
"LeadingTrivia": {
"Newline": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public async Task GenerateCode(MinimalApiGeneratorCommandLineModel model)

if (!string.IsNullOrEmpty(modelTypeAndContextModel.DbContextFullName) && CalledFromCommandline)
{
EFValidationUtil.ValidateEFDependencies(ProjectContext.PackageDependencies, useSqlite: false);
EFValidationUtil.ValidateEFDependencies(ProjectContext.PackageDependencies, useSqlite: model.UseSqlite);
}

var templateModel = new MinimalApiModel(modelTypeAndContextModel.ModelType, modelTypeAndContextModel.DbContextFullName, model.EndpintsClassName)
Expand All @@ -92,7 +92,8 @@ public async Task GenerateCode(MinimalApiGeneratorCommandLineModel model)
ModelMetadata = modelTypeAndContextModel.ContextProcessingResult?.ModelMetadata,
NullableEnabled = "enable".Equals(AppInfo?.WorkspaceHelper?.GetMsBuildProperty("Nullable"), StringComparison.OrdinalIgnoreCase),
OpenAPI = model.OpenApi,
MethodName = $"Map{modelTypeAndContextModel.ModelType.Name}Endpoints"
MethodName = $"Map{modelTypeAndContextModel.ModelType.Name}Endpoints",
UseSqlite = model.UseSqlite
};

var endpointsModel = ModelTypesLocator.GetAllTypes().FirstOrDefault(t => t.Name.Equals(model.EndpintsClassName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public class MinimalApiGeneratorCommandLineModel
[Option(Name = "endpointsNamespace", ShortName = "namespace", Description = "Specify the name of the namespace to use for the generated controller")]
public string EndpointsNamespace { get; set; }

[Option(Name = "useSqlite", ShortName = "sqlite", Description = "Flag to specify if DbContext should use SQLite instead of SQL Server.")]
public bool UseSqlite { get; set; }

public MinimalApiGeneratorCommandLineModel()
{
}
Expand All @@ -33,6 +36,7 @@ protected MinimalApiGeneratorCommandLineModel(MinimalApiGeneratorCommandLineMode
RelativeFolderPath = copyFrom.RelativeFolderPath;
OpenApi = copyFrom.OpenApi;
EndpointsNamespace = copyFrom.EndpointsNamespace;
UseSqlite = copyFrom.UseSqlite;
}

public MinimalApiGeneratorCommandLineModel Clone()
Expand Down
3 changes: 3 additions & 0 deletions src/Scaffolding/VS.Web.CG.Mvc/Minimal Api/MinimalApiModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public MinimalApiModel(
//If CRUD endpoints support Open API
public bool OpenAPI { get; set; }

//Sqlite for sqlite and mac/linux scenarios.
public bool UseSqlite { get; set; }

//Generated namespace for a Endpoints class/file. If using an existing file, does not apply.
public string EndpointsNamespace { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/Scaffolding/VS.Web.CG.Mvc/ModelMetadataUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ internal static async Task<ModelTypeAndContextModel> GetModelEFMetadataMinimalAs
dbContextFullName,
model,
areaName,
useSqlite: false);
useSqlite: commandLineModel.UseSqlite);
}

return new ModelTypeAndContextModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ internal static SyntaxNode ModifyMethod(SyntaxNode originalMethod, CodeSnippet c
internal static SyntaxNode UpdateMethod(SyntaxNode originalMethod, CodeSnippet codeChange)
{
var children = GetDescendantNodes(originalMethod);
if (ProjectModifierHelper.StatementExists(children, codeChange.Block))
//check for CodeChange.Block and CodeChange.CheckBlock for block's are easy to check.
if (ProjectModifierHelper.StatementExists(children, codeChange.Block) || (!string.IsNullOrEmpty(codeChange.CheckBlock) && ProjectModifierHelper.StatementExists(children, codeChange.CheckBlock)))
{
return originalMethod;
}
Expand Down

0 comments on commit e58fc93

Please sign in to comment.