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>
44 changes: 44 additions & 0 deletions azure-pipelines-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,31 @@ stages:
steps:
- checkout: self
clean: true
# Install additional .NET SDKs 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 AND matching SDKs (with MSBuild.dll)
# to be present on the agent.
- task: UseDotNet@2
displayName: Install .NET 8 SDK
inputs:
packageType: sdk
version: 8.x
installationPath: $(Build.SourcesDirectory)/.dotnet
- task: UseDotNet@2
displayName: Install .NET 9 SDK
inputs:
packageType: sdk
version: 9.x
installationPath: $(Build.SourcesDirectory)/.dotnet
- task: UseDotNet@2
displayName: Install .NET 10 SDK
inputs:
packageType: sdk
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 +119,25 @@ stages:
steps:
- checkout: self
clean: true
- task: UseDotNet@2
displayName: Install .NET 8 SDK
inputs:
packageType: sdk
version: 8.x
installationPath: $(Build.SourcesDirectory)/.dotnet
- task: UseDotNet@2
displayName: Install .NET 9 SDK
inputs:
packageType: sdk
version: 9.x
installationPath: $(Build.SourcesDirectory)/.dotnet
- task: UseDotNet@2
displayName: Install .NET 10 SDK
inputs:
packageType: sdk
version: 10.x
includePreviewVersions: true
installationPath: $(Build.SourcesDirectory)/.dotnet
- script: eng/common/build.sh
--configuration $(_BuildConfig)
--prepareMachine
Expand Down
25 changes: 25 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,31 @@ extends:
steps:
- checkout: self
clean: true
# Install additional .NET SDKs 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 AND matching SDKs (with MSBuild.dll)
# to be present on the agent.
- task: UseDotNet@2
displayName: Install .NET 8 SDK
inputs:
packageType: sdk
version: 8.x
installationPath: $(Build.SourcesDirectory)/.dotnet
- task: UseDotNet@2
displayName: Install .NET 9 SDK
inputs:
packageType: sdk
version: 9.x
installationPath: $(Build.SourcesDirectory)/.dotnet
- task: UseDotNet@2
displayName: Install .NET 10 SDK
inputs:
packageType: sdk
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
6 changes: 3 additions & 3 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<SystemCommandLinePackageVersion>2.0.0</SystemCommandLinePackageVersion>
<MicrosoftApplicationInsightsWorkerServicePackageVersion>2.22.0</MicrosoftApplicationInsightsWorkerServicePackageVersion>
<MicrosoftDotNetPlatformAbstractionsVersion>3.1.6</MicrosoftDotNetPlatformAbstractionsVersion>
<NugetProtocolVersion>7.3.1</NugetProtocolVersion>
<NugetProtocolVersion>7.0.1</NugetProtocolVersion>
</PropertyGroup>
<PropertyGroup>
<VersionPrefix>11.0.0</VersionPrefix>
Expand Down Expand Up @@ -123,7 +123,7 @@
<!-- Microsoft.Extensions.CommandLineUtils.Sources -->
<MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion>6.0.0-preview.3.21166.3</MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion>
<NewtonsoftJsonPackageVersion>13.0.3</NewtonsoftJsonPackageVersion>
<NuGetPackagingVersion>7.3.1</NuGetPackagingVersion>
<NuGetPackagingVersion>6.12.1</NuGetPackagingVersion>
<HumanizerCorePackageVersion>3.0.1</HumanizerCorePackageVersion>
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- Everything below here are Packages only used by test projects -->
Expand Down Expand Up @@ -158,7 +158,7 @@
<CodeAnalysisVersion>$(MicrosoftCodeAnalysisVersion)</CodeAnalysisVersion>
<MicrosoftGraphVersion>5.66.0</MicrosoftGraphVersion>
<MicrosoftIdentityClientExtensionsMsalVersion>4.73.1</MicrosoftIdentityClientExtensionsMsalVersion>
<NuGetProjectModelVersion>7.3.1</NuGetProjectModelVersion>
<NuGetProjectModelVersion>6.12.1</NuGetProjectModelVersion>
<SystemCommandLineVersion>2.0.0</SystemCommandLineVersion>
<SystemSecurityCryptographyProtectedDataVersion>9.0.11</SystemSecurityCryptographyProtectedDataVersion>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal static class BlazorIdentityHelper

internal static string GetFormattedRelativeIdentityFile(string fullFileName)
{
string identifier = "BlazorIdentity\\";
string identifier = "BlazorIdentity" + Path.DirectorySeparatorChar;
int index = fullFileName.IndexOf(identifier);
if (index != -1)
{
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 @@ -37,33 +37,56 @@ public NuGetVersionService(IEnvironmentService environmentService)
/// </summary>
/// <param name="packageId">the ID of the NuGet package</param>
/// <param name="MajorVersion">the .NET major version</param>
/// <param name="projectDirectory">
/// Optional directory of the project being scaffolded. When provided, NuGet settings are loaded
/// from this directory so that the same package sources used by <c>dotnet add package</c> are
/// queried, rather than the repo-root NuGet.config (which may have <c>&lt;clear /&gt;</c> and
/// no nuget.org feed).
/// </param>
/// <returns></returns>
public async Task<NuGetVersion?> GetLatestPackageForNetVersionAsync(string packageId, int MajorVersion)
public async Task<NuGetVersion?> GetLatestPackageForNetVersionAsync(string packageId, int MajorVersion, string? projectDirectory = null)
{
IEnumerable<NuGetVersion> versions = await GetVersionsForPackageAsync(packageId);
IEnumerable<NuGetVersion> versions = await GetVersionsForPackageAsync(packageId, projectDirectory);

// Filter for the specified .NET major version
var compatibleVersions = versions.Where(v => v.Major == MajorVersion).OrderByDescending(v => v);
return compatibleVersions.FirstOrDefault();
}

private async Task<IEnumerable<NuGetVersion>> GetVersionsForPackageAsync(string packageId)
private async Task<IEnumerable<NuGetVersion>> GetVersionsForPackageAsync(string packageId, string? projectDirectory = null)
{
// When a project directory is provided, load settings from there so that the package
// sources match the context used by 'dotnet add package' (e.g. a temp project directory
// that is outside the repo and therefore does not inherit the repo-root NuGet.config with
// <clear /> that strips away nuget.org).
ISettings effectiveSettings = projectDirectory is not null
? Settings.LoadDefaultSettings(projectDirectory)
: _settings;
PackageSourceProvider effectiveSourceProvider = projectDirectory is not null
? new PackageSourceProvider(effectiveSettings)
: _sourceProvider;
CachingSourceProvider effectiveCachingProvider = projectDirectory is not null
? new CachingSourceProvider(effectiveSourceProvider)
: _cachingProvider;
PackageSourceMapping? effectiveSourceMapping = projectDirectory is not null
? PackageSourceMapping.GetPackageSourceMapping(effectiveSettings)
: _sourceMapping;

// Load package sources and filter enabled ones
IEnumerable<PackageSource> packageSources = _sourceProvider.LoadPackageSources().Where(s => s.IsEnabled);
IEnumerable<PackageSource> packageSources = effectiveSourceProvider.LoadPackageSources().Where(s => s.IsEnabled);

// Check if package source mapping is enabled
if (_sourceMapping?.IsEnabled == true)
if (effectiveSourceMapping?.IsEnabled == true)
{
IReadOnlyList<string> configuredSources = _sourceMapping.GetConfiguredPackageSources(packageId);
IReadOnlyList<string> configuredSources = effectiveSourceMapping.GetConfiguredPackageSources(packageId);
if (configuredSources.Any())
{
packageSources = packageSources.Where(s => configuredSources.Contains(s.Name));
}
}

List<SourceRepository> repositories = [.. packageSources
.Select(source => _cachingProvider.CreateRepository(source))];
.Select(source => effectiveCachingProvider.CreateRepository(source))];

if (repositories.Count == 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,20 @@ internal static class PackageExtensions
/// <param name="targetFramework">The target framework identifier used to determine the appropriate package version. For example, "net6.0".</param>
/// <param name="nugetVersionHelper">The NuGet version helper to use for version resolution.</param>
/// <param name="logger">The logger to use for logging messages.</param>
/// <param name="projectDirectory">
/// Optional directory of the project being scaffolded. When provided, NuGet settings are loaded
/// from this directory so that the same package sources used by <c>dotnet add package</c> are
/// queried.
/// </param>
/// <returns>A package instance with the version property set to the resolved version for the specified target framework, or
/// the original package if the version is already set or cannot be resolved.</returns>
public static async Task<Package> WithResolvedVersionAsync(this Package package, TargetFramework? targetFramework, NuGetVersionService nugetVersionHelper, ILogger? logger = null)
public static async Task<Package> WithResolvedVersionAsync(this Package package, TargetFramework? targetFramework, NuGetVersionService nugetVersionHelper, ILogger? logger = null, string? projectDirectory = null)
{
if (package.PackageVersion is not null)
{
return package;
}
NuGetVersion? resolvedVersion = await package.GetVersionForTargetFrameworkAsync(targetFramework, nugetVersionHelper, logger);
NuGetVersion? resolvedVersion = await package.GetVersionForTargetFrameworkAsync(targetFramework, nugetVersionHelper, logger, projectDirectory);
if (resolvedVersion is null)
{
return package;
Expand All @@ -59,7 +64,7 @@ public static async Task<Package> WithResolvedVersionAsync(this Package package,
/// <param name="logger">The logger to use for logging messages.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the corresponding NuGet package
/// version if available; otherwise, <see langword="null"/> if the package does not require a version or target framework is not supported.</returns>
private static Task<NuGetVersion?> GetVersionForTargetFrameworkAsync(this Package package, TargetFramework? targetFramework, NuGetVersionService nugetVersionHelper, ILogger? logger = null)
private static Task<NuGetVersion?> GetVersionForTargetFrameworkAsync(this Package package, TargetFramework? targetFramework, NuGetVersionService nugetVersionHelper, ILogger? logger = null, string? projectDirectory = null)
{
if (!package.IsVersionRequired)
{
Expand All @@ -74,19 +79,19 @@ public static async Task<Package> WithResolvedVersionAsync(this Package package,

if (targetFramework is TargetFramework.Net8)
{
return nugetVersionHelper.GetLatestPackageForNetVersionAsync(package.Name, 8);
return nugetVersionHelper.GetLatestPackageForNetVersionAsync(package.Name, 8, projectDirectory);
}
else if (targetFramework is TargetFramework.Net9)
{
return nugetVersionHelper.GetLatestPackageForNetVersionAsync(package.Name, 9);
return nugetVersionHelper.GetLatestPackageForNetVersionAsync(package.Name, 9, projectDirectory);
}
else if (targetFramework is TargetFramework.Net10)
{
return nugetVersionHelper.GetLatestPackageForNetVersionAsync(package.Name, 10);
return nugetVersionHelper.GetLatestPackageForNetVersionAsync(package.Name, 10, projectDirectory);
}
else if (targetFramework is TargetFramework.Net11)
{
return nugetVersionHelper.GetLatestPackageForNetVersionAsync(package.Name, 11);
return nugetVersionHelper.GetLatestPackageForNetVersionAsync(package.Name, 11, projectDirectory);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,17 @@ public override async Task<bool> ExecuteAsync(ScaffolderContext context, Cancell
{
// Try to get the target framework from the context
TargetFramework? targetFramework = context.GetSpecifiedTargetFramework();
string? projectDirectory = !string.IsNullOrEmpty(ProjectPath)
? Path.GetDirectoryName(Path.GetFullPath(ProjectPath))
: null;

foreach (Package package in Packages)
{
string? packageVersion = null;
Package resolvedPackage = package;
if (package.IsVersionRequired && !Prerelease)
{
resolvedPackage = await package.WithResolvedVersionAsync(targetFramework, _nugetVersionHelper, _logger);
resolvedPackage = await package.WithResolvedVersionAsync(targetFramework, _nugetVersionHelper, _logger, projectDirectory);
packageVersion = resolvedPackage.PackageVersion;
}

Expand Down
Loading
Loading