Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
<NoWarn>$(NoWarn);NU1507</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="Azure.Identity" Version="$(AzureIdentityVersion)" />
<PackageVersion Include="Humanizer.Core" Version="$(HumanizerCorePackageVersion)" />
<PackageVersion Include="Microsoft.AspNetCore.Identity.UI" Version="10.0.3" />
<PackageVersion Include="Microsoft.Build.Locator" Version="$(MicrosoftBuildLocatorPackageVersion)" />
<PackageVersion Include="Microsoft.Build" Version="$(MicrosoftBuildPackageVersion)" />
<PackageVersion Include="Microsoft.Build.Framework" Version="$(MicrosoftBuildPackageVersion)" />
Expand Down Expand Up @@ -51,9 +51,8 @@
<PackageVersion Include="System.Security.Cryptography.ProtectedData" Version="$(SystemSecurityCryptographyProtectedDataVersion)" />
<PackageVersion Include="xunit.skippablefact" Version="$(XunitSkippableFactPackageVersion)" />
</ItemGroup>

<ItemGroup>
<!-- Pinned transitive package versions for Component Governance alerts -->
<PackageVersion Include="System.Formats.Asn1" Version="$(SystemFormatsAsn1Version)" />
</ItemGroup>
</Project>
</Project>
62 changes: 62 additions & 0 deletions azure-pipelines-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,30 @@ stages:
steps:
- checkout: self
clean: true
# Install additional .NET runtimes needed by integration tests.
# The global.json SDK is .NET 11 preview, but the multi-targeted
# dotnet-scaffold tool also builds for net8.0, net9.0, and net10.0.
# Integration tests invoke 'dotnet run --framework net8.0/net9.0/net10.0'
# which requires those runtimes to be present on the agent.
- task: UseDotNet@2
displayName: Install .NET 8 runtime
inputs:
packageType: runtime
version: 8.x
installationPath: $(Build.SourcesDirectory)/.dotnet
- task: UseDotNet@2
displayName: Install .NET 9 runtime
inputs:
packageType: runtime
version: 9.x
installationPath: $(Build.SourcesDirectory)/.dotnet
- task: UseDotNet@2
displayName: Install .NET 10 runtime
inputs:
packageType: runtime
version: 10.x
includePreviewVersions: true
installationPath: $(Build.SourcesDirectory)/.dotnet
# Use utility script to run script command dependent on agent OS.
- script: $(_Script)
-configuration $(_BuildConfig)
Expand All @@ -94,6 +118,25 @@ stages:
steps:
- checkout: self
clean: true
- task: UseDotNet@2
displayName: Install .NET 8 runtime
inputs:
packageType: runtime
version: 8.x
installationPath: $(Build.SourcesDirectory)/.dotnet
- task: UseDotNet@2
displayName: Install .NET 9 runtime
inputs:
packageType: runtime
version: 9.x
installationPath: $(Build.SourcesDirectory)/.dotnet
- task: UseDotNet@2
displayName: Install .NET 10 runtime
inputs:
packageType: runtime
version: 10.x
includePreviewVersions: true
installationPath: $(Build.SourcesDirectory)/.dotnet
- script: eng/common/build.sh
--configuration $(_BuildConfig)
--prepareMachine
Expand All @@ -117,6 +160,25 @@ stages:
steps:
- checkout: self
clean: true
- task: UseDotNet@2
displayName: Install .NET 8 runtime
inputs:
packageType: runtime
version: 8.x
installationPath: $(Build.SourcesDirectory)/.dotnet
- task: UseDotNet@2
displayName: Install .NET 9 runtime
inputs:
packageType: runtime
version: 9.x
installationPath: $(Build.SourcesDirectory)/.dotnet
- task: UseDotNet@2
displayName: Install .NET 10 runtime
inputs:
packageType: runtime
version: 10.x
includePreviewVersions: true
installationPath: $(Build.SourcesDirectory)/.dotnet
- script: eng/common/build.sh
--configuration $(_BuildConfig)
--prepareMachine
Expand Down
24 changes: 24 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,30 @@ extends:
steps:
- checkout: self
clean: true
# Install additional .NET runtimes needed by integration tests.
# The global.json SDK is .NET 11 preview, but the multi-targeted
# dotnet-scaffold tool also builds for net8.0, net9.0, and net10.0.
# Integration tests invoke 'dotnet run --framework net8.0/net9.0/net10.0'
# which requires those runtimes to be present on the agent.
- task: UseDotNet@2
displayName: Install .NET 8 runtime
inputs:
packageType: runtime
version: 8.x
installationPath: $(Build.SourcesDirectory)/.dotnet
- task: UseDotNet@2
displayName: Install .NET 9 runtime
inputs:
packageType: runtime
version: 9.x
installationPath: $(Build.SourcesDirectory)/.dotnet
- task: UseDotNet@2
displayName: Install .NET 10 runtime
inputs:
packageType: runtime
version: 10.x
includePreviewVersions: true
installationPath: $(Build.SourcesDirectory)/.dotnet
# Use utility script to run script command dependent on agent OS.
- script: $(_Script)
-configuration $(_BuildConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ public static bool AddPackage(string packageName, ILogger logger, string? projec
logger.LogInformation($"\nAdding package '{packageDisplayName}'...");
var runner = DotnetCliRunner.CreateDotNet("add", arguments);

// Set working directory to the project's directory so that NuGet.config
// resolution uses the project's NuGet.config rather than inheriting feeds
// from the current working directory (which may have preview/dev feeds).
if (!string.IsNullOrEmpty(projectFile))
{
var projectDir = Path.GetDirectoryName(Path.GetFullPath(projectFile));
if (!string.IsNullOrEmpty(projectDir))
{
runner._psi.WorkingDirectory = projectDir;
}
}

// Buffer the output here because we'll only display it in the failure scenario
var exitCode = runner.ExecuteAndCaptureOutput(out var stdOut, out var stdErr);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ public void Initialize()
}

/// <summary>
/// find the newest dotnet sdk on disk first, if none found, use the MsBuildLocator.RegisterDefaults().
/// Find a compatible dotnet SDK on disk and register its MSBuild.
/// Picks the newest SDK whose major version is less than or equal to the current runtime's major version,
/// so that loading MSBuild assemblies does not pull in a higher System.Runtime than the runtime supports.
/// Falls back to <see cref="MSBuildLocator.RegisterDefaults"/> when no compatible SDK is found.
/// </summary>
/// <returns></returns>
private void RegisterMsbuild()
{
if (!MSBuildLocator.IsRegistered)
Expand All @@ -36,16 +38,22 @@ private void RegisterMsbuild()
return;
}

//register newest MSBuild from the newest dotnet sdk installed.
int runtimeMajor = Environment.Version.Major;

// Find SDKs whose major version is compatible with the running runtime.
// A .NET X runtime can safely load MSBuild from SDK version X.y.z (same major)
// but NOT from a higher major version (e.g. SDK 11.x on .NET 8 runtime).
var sdkPaths = Directory.GetDirectories(sdkBasePath)
.Select(d => new { Path = d, new DirectoryInfo(d).Name })
.Where(d => Version.TryParse(d.Name.Split('-')[0], out _))
.OrderByDescending(d => Version.Parse(d.Name.Split('-')[0]))
.Select(d => new { Path = d, DirName = new DirectoryInfo(d).Name })
.Where(d => Version.TryParse(d.DirName.Split('-')[0], out _))
.Select(d => new { d.Path, Version = Version.Parse(d.DirName.Split('-')[0]) })
.Where(d => d.Version.Major <= runtimeMajor)
.OrderByDescending(d => d.Version)
.Select(d => d.Path);

if (!sdkPaths.Any())
{
_logger.LogInformation($"Could not find a .NET SDK at the default locations.");
_logger.LogInformation($"Could not find a .NET SDK compatible with runtime version {Environment.Version} at the default locations.");
MSBuildLocator.RegisterDefaults();
return;
}
Expand All @@ -55,7 +63,7 @@ private void RegisterMsbuild()
var msbuildPath = Path.Combine(sdkPath, "MSBuild.dll");
if (File.Exists(msbuildPath))
{
// Register the latest SDK
// Register the best compatible SDK
MSBuildLocator.RegisterMSBuildPath(sdkPath);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal static DbContextInfo GetDbContextInfo(
dbContextInfo.NewDbSetStatement = modelInfo is null ?
string.Empty : $"public DbSet<{modelInfo.ModelFullName}> {modelInfo.ModelTypeName} {{ get; set; }} = default!;";
dbContextInfo.DbContextClassName = dbContextClassName;
dbContextInfo.DbContextClassPath = CommandHelpers.GetNewFilePath(projectPath, dbContextClassName);
dbContextInfo.DbContextClassPath = AspNetDbContextHelper.GetIdentityDataContextPath(projectPath, dbContextClassName);
dbContextInfo.DatabaseProvider = dbProvider;
dbContextInfo.EntitySetVariableName = modelInfo?.ModelTypeName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,40 @@
}
}
]
},
}
}
},
{
"FileName": "Program.cs",
"Usings": [
"Microsoft.EntityFrameworkCore"
],
"Options": [
"EfScenario"
],
"Methods": {
"Global": {
"CodeChanges": [
{
"InsertAfter": "WebApplication.CreateBuilder",
"CheckBlock": "builder.Configuration.GetConnectionString",
"Block": "\nvar connectionString = builder.Configuration.GetConnectionString(\"$(ConnectionStringName)\") ?? throw new InvalidOperationException(\"Connection string '$(ConnectionStringName)' not found.\")"
},
{
"InsertAfter": "builder.Configuration.GetConnectionString",
"CheckBlock": "builder.Services.AddDbContext",
"Block": "builder.Services.AddDbContext<$(DbContextName)>(options => options.$(UseDbMethod))",
"LeadingTrivia": {
"Newline": true
}
}
]
}
}
},
{
"FileName": "Program.cs",
"Methods": {
"OpenApi": {
"CodeChanges": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ public virtual string TransformText()
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind(""Title,ReleaseDate,Genre,Price"")] ");
this.Write(this.ToStringHelper.ToStringWithCulture(modelName));
this.Write(" movie)\r\n {\r\n if (ModelState.IsValid)\r\n {\r\n _context." +
this.Write(" ");
this.Write(this.ToStringHelper.ToStringWithCulture(modelNameLowerInv));
this.Write(")\r\n {\r\n if (ModelState.IsValid)\r\n {\r\n _context." +
"Add(");
this.Write(this.ToStringHelper.ToStringWithCulture(modelNameLowerInv));
this.Write(");\r\n await _context.SaveChangesAsync();\r\n return RedirectTo" +
Expand Down Expand Up @@ -141,7 +143,9 @@ public virtual string TransformText()
this.Write(this.ToStringHelper.ToStringWithCulture(primaryKeyNameLowerInv));
this.Write(", [Bind(\"Id,Title,ReleaseDate,Genre,Price\")] ");
this.Write(this.ToStringHelper.ToStringWithCulture(modelName));
this.Write(" movie)\r\n {\r\n if (");
this.Write(" ");
this.Write(this.ToStringHelper.ToStringWithCulture(modelNameLowerInv));
this.Write(")\r\n {\r\n if (");
this.Write(this.ToStringHelper.ToStringWithCulture(primaryKeyNameLowerInv));
this.Write(" != ");
this.Write(this.ToStringHelper.ToStringWithCulture(modelNameLowerInv));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class <#= Model.ControllerName #> : Controller
// For more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("Title,ReleaseDate,Genre,Price")] <#= modelName #> movie)
public async Task<IActionResult> Create([Bind("Title,ReleaseDate,Genre,Price")] <#= modelName #> <#= modelNameLowerInv #>)
{
if (ModelState.IsValid)
{
Expand Down Expand Up @@ -108,7 +108,7 @@ public class <#= Model.ControllerName #> : Controller
// For more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(<#= primaryKeyTypeName #>? <#= primaryKeyNameLowerInv #>, [Bind("Id,Title,ReleaseDate,Genre,Price")] <#= modelName #> movie)
public async Task<IActionResult> Edit(<#= primaryKeyTypeName #>? <#= primaryKeyNameLowerInv #>, [Bind("Id,Title,ReleaseDate,Genre,Price")] <#= modelName #> <#= modelNameLowerInv #>)
{
if (<#= primaryKeyNameLowerInv #> != <#= modelNameLowerInv #>.<#= primaryKeyName #>)
{
Expand Down
Loading
Loading