Skip to content

Commit a795388

Browse files
[main] Source code updates from dotnet/sdk (#2482)
Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
1 parent 6c5f086 commit a795388

45 files changed

Lines changed: 1435 additions & 56 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/sdk/.github/copilot-instructions.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ Coding Style and Changes:
22
- Code should match the style of the file it's in.
33
- Changes should be minimal to resolve a problem in a clean way.
44
- User-visible changes to behavior should be considered carefully before committing. They should always be flagged.
5+
- When generating code, run `dotnet format` to ensure uniform formatting.
6+
- Prefer using file-based namespaces for new code.
7+
- Do not allow unused `using` directives to be committed.
58

69
Testing:
710
- Large changes should always include test changes.

src/sdk/NuGet.config

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<!-- Begin: Package sources from dotnet-aspire -->
77
<!-- End: Package sources from dotnet-aspire -->
88
<!-- Begin: Package sources from dotnet-runtime -->
9-
<add key="darc-int-dotnet-runtime-893c2eb" value="https://pkgs.dev.azure.com/dnceng/internal/_packaging/darc-int-dotnet-runtime-893c2ebb/nuget/v3/index.json" />
109
<!-- End: Package sources from dotnet-runtime -->
1110
<!--End: Package sources managed by Dependency Flow automation. Do not edit the sources above.-->
1211
<add key="dotnet6" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json" />
@@ -38,7 +37,6 @@
3837
<clear />
3938
<!--Begin: Package sources managed by Dependency Flow automation. Do not edit the sources below.-->
4039
<!-- Begin: Package sources from dotnet-runtime -->
41-
<add key="darc-int-dotnet-runtime-893c2eb" value="true" />
4240
<!-- End: Package sources from dotnet-runtime -->
4341
<!--End: Package sources managed by Dependency Flow automation. Do not edit the sources above.-->
4442
</disabledPackageSources>

src/sdk/eng/Version.Details.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ This file should be imported by eng/Versions.props
140140
<!-- dotnet/core-setup dependencies -->
141141
<NETStandardLibraryRefPackageVersion>2.1.0</NETStandardLibraryRefPackageVersion>
142142
<!-- microsoft/testfx dependencies -->
143-
<MicrosoftTestingPlatformPackageVersion>1.9.0-preview.25464.1</MicrosoftTestingPlatformPackageVersion>
144-
<MSTestPackageVersion>3.11.0-preview.25464.1</MSTestPackageVersion>
143+
<MicrosoftTestingPlatformPackageVersion>1.9.0-preview.25466.1</MicrosoftTestingPlatformPackageVersion>
144+
<MSTestPackageVersion>3.11.0-preview.25466.1</MSTestPackageVersion>
145145
</PropertyGroup>
146146
<!--Property group for alternate package version names-->
147147
<PropertyGroup>

src/sdk/eng/Version.Details.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,13 +553,13 @@
553553
<Uri>https://github.com/dotnet/dotnet</Uri>
554554
<Sha>7ac1ca67bb1fb8a381c1c94a9f82a97725f0ccf3</Sha>
555555
</Dependency>
556-
<Dependency Name="Microsoft.Testing.Platform" Version="1.9.0-preview.25464.1">
556+
<Dependency Name="Microsoft.Testing.Platform" Version="1.9.0-preview.25466.1">
557557
<Uri>https://github.com/microsoft/testfx</Uri>
558-
<Sha>b7507dc8a6007e132d8809edc2ddf0065bd0ec4e</Sha>
558+
<Sha>1756c7f849409a918a47338b8ae26d939f2a320c</Sha>
559559
</Dependency>
560-
<Dependency Name="MSTest" Version="3.11.0-preview.25464.1">
560+
<Dependency Name="MSTest" Version="3.11.0-preview.25466.1">
561561
<Uri>https://github.com/microsoft/testfx</Uri>
562-
<Sha>b7507dc8a6007e132d8809edc2ddf0065bd0ec4e</Sha>
562+
<Sha>1756c7f849409a918a47338b8ae26d939f2a320c</Sha>
563563
</Dependency>
564564
<Dependency Name="Microsoft.Extensions.Configuration.Ini" Version="10.0.0-rc.2.25427.104">
565565
<Uri>https://github.com/dotnet/dotnet</Uri>

src/sdk/src/Cli/dotnet/CliStrings.resx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,18 @@ setx PATH "%PATH%;{0}"
512512
<data name="CmdEnvironmentVariableDescription" xml:space="preserve">
513513
<value>Sets the value of an environment variable.
514514
Creates the variable if it does not exist, overrides if it does.
515+
This argument can be specified multiple times to provide multiple variables.
516+
517+
Examples:
518+
-e VARIABLE=abc
519+
-e VARIABLE="value with spaces"
520+
-e VARIABLE="value;seperated with;semicolons"
521+
-e VAR1=abc -e VAR2=def -e VAR3=ghi
522+
</value>
523+
</data>
524+
<data name="CmdTestEnvironmentVariableDescription" xml:space="preserve">
525+
<value>Sets the value of an environment variable.
526+
Creates the variable if it does not exist, overrides if it does.
515527
This will force the tests to be run in an isolated process.
516528
This argument can be specified multiple times to provide multiple variables.
517529

src/sdk/src/Cli/dotnet/Commands/Run/RunCommand.cs

Lines changed: 146 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,15 @@ public int Execute()
124124

125125
Func<ProjectCollection, ProjectInstance>? projectFactory = null;
126126
RunProperties? cachedRunProperties = null;
127+
VirtualProjectBuildingCommand? virtualCommand = null;
127128
if (ShouldBuild)
128129
{
129130
if (string.Equals("true", launchSettings?.DotNetRunMessages, StringComparison.OrdinalIgnoreCase))
130131
{
131132
Reporter.Output.WriteLine(CliCommandStrings.RunCommandBuilding);
132133
}
133134

134-
EnsureProjectIsBuilt(out projectFactory, out cachedRunProperties);
135+
EnsureProjectIsBuilt(out projectFactory, out cachedRunProperties, out virtualCommand);
135136
}
136137
else
137138
{
@@ -143,11 +144,11 @@ public int Execute()
143144
if (EntryPointFileFullPath is not null)
144145
{
145146
Debug.Assert(!ReadCodeFromStdin);
146-
var command = CreateVirtualCommand();
147-
command.MarkArtifactsFolderUsed();
147+
virtualCommand = CreateVirtualCommand();
148+
virtualCommand.MarkArtifactsFolderUsed();
148149

149-
var cacheEntry = command.GetPreviousCacheEntry();
150-
projectFactory = CanUseRunPropertiesForCscBuiltProgram(BuildLevel.None, cacheEntry) ? null : command.CreateProjectInstance;
150+
var cacheEntry = virtualCommand.GetPreviousCacheEntry();
151+
projectFactory = CanUseRunPropertiesForCscBuiltProgram(BuildLevel.None, cacheEntry) ? null : virtualCommand.CreateProjectInstance;
151152
cachedRunProperties = cacheEntry?.Run;
152153
}
153154
}
@@ -163,6 +164,9 @@ public int Execute()
163164
targetCommand.EnvironmentVariable(name, value);
164165
}
165166

167+
// Send telemetry about the run operation
168+
SendRunTelemetry(launchSettings, virtualCommand);
169+
166170
// Ignore Ctrl-C for the remainder of the command's execution
167171
Console.CancelKeyPress += (sender, e) => { e.Cancel = true; };
168172

@@ -297,22 +301,23 @@ internal bool TryGetLaunchProfileSettingsIfNeeded(out ProjectLaunchSettingsModel
297301
}
298302
}
299303

300-
private void EnsureProjectIsBuilt(out Func<ProjectCollection, ProjectInstance>? projectFactory, out RunProperties? cachedRunProperties)
304+
private void EnsureProjectIsBuilt(out Func<ProjectCollection, ProjectInstance>? projectFactory, out RunProperties? cachedRunProperties, out VirtualProjectBuildingCommand? virtualCommand)
301305
{
302306
int buildResult;
303307
if (EntryPointFileFullPath is not null)
304308
{
305-
var command = CreateVirtualCommand();
306-
buildResult = command.Execute();
307-
projectFactory = CanUseRunPropertiesForCscBuiltProgram(command.LastBuild.Level, command.LastBuild.Cache?.PreviousEntry) ? null : command.CreateProjectInstance;
308-
cachedRunProperties = command.LastBuild.Cache?.CurrentEntry.Run;
309+
virtualCommand = CreateVirtualCommand();
310+
buildResult = virtualCommand.Execute();
311+
projectFactory = CanUseRunPropertiesForCscBuiltProgram(virtualCommand.LastBuild.Level, virtualCommand.LastBuild.Cache?.PreviousEntry) ? null : virtualCommand.CreateProjectInstance;
312+
cachedRunProperties = virtualCommand.LastBuild.Cache?.CurrentEntry.Run;
309313
}
310314
else
311315
{
312316
Debug.Assert(ProjectFileFullPath is not null);
313317

314318
projectFactory = null;
315319
cachedRunProperties = null;
320+
virtualCommand = null;
316321
buildResult = new RestoringCommand(
317322
MSBuildArgs.CloneWithExplicitArgs([ProjectFileFullPath, .. MSBuildArgs.OtherMSBuildArgs]),
318323
NoRestore,
@@ -753,4 +758,135 @@ public static ParseResult ModifyParseResultForShorthandProjectOption(ParseResult
753758
var newParseResult = Parser.Parse(tokensToParse);
754759
return newParseResult;
755760
}
761+
762+
/// <summary>
763+
/// Sends telemetry about the run operation.
764+
/// </summary>
765+
private void SendRunTelemetry(
766+
ProjectLaunchSettingsModel? launchSettings,
767+
VirtualProjectBuildingCommand? virtualCommand)
768+
{
769+
try
770+
{
771+
if (virtualCommand != null)
772+
{
773+
SendFileBasedTelemetry(launchSettings, virtualCommand);
774+
}
775+
else
776+
{
777+
SendProjectBasedTelemetry(launchSettings);
778+
}
779+
}
780+
catch (Exception ex)
781+
{
782+
// Silently ignore telemetry errors to not affect the run operation
783+
if (CommandLoggingContext.IsVerbose)
784+
{
785+
Reporter.Verbose.WriteLine($"Failed to send run telemetry: {ex}");
786+
}
787+
}
788+
}
789+
790+
/// <summary>
791+
/// Builds and sends telemetry data for file-based app runs.
792+
/// </summary>
793+
private void SendFileBasedTelemetry(
794+
ProjectLaunchSettingsModel? launchSettings,
795+
VirtualProjectBuildingCommand virtualCommand)
796+
{
797+
Debug.Assert(EntryPointFileFullPath != null);
798+
var projectIdentifier = RunTelemetry.GetFileBasedIdentifier(EntryPointFileFullPath, Sha256Hasher.Hash);
799+
800+
var directives = virtualCommand.Directives;
801+
var sdkCount = RunTelemetry.CountSdks(directives);
802+
var packageReferenceCount = RunTelemetry.CountPackageReferences(directives);
803+
var projectReferenceCount = RunTelemetry.CountProjectReferences(directives);
804+
var additionalPropertiesCount = RunTelemetry.CountAdditionalProperties(directives);
805+
806+
RunTelemetry.TrackRunEvent(
807+
isFileBased: true,
808+
projectIdentifier: projectIdentifier,
809+
launchProfile: LaunchProfile,
810+
noLaunchProfile: NoLaunchProfile,
811+
launchSettings: launchSettings,
812+
sdkCount: sdkCount,
813+
packageReferenceCount: packageReferenceCount,
814+
projectReferenceCount: projectReferenceCount,
815+
additionalPropertiesCount: additionalPropertiesCount,
816+
usedMSBuild: virtualCommand.LastBuild.Level is BuildLevel.All,
817+
usedRoslynCompiler: virtualCommand.LastBuild.Level is BuildLevel.Csc);
818+
}
819+
820+
/// <summary>
821+
/// Builds and sends telemetry data for project-based app runs.
822+
/// </summary>
823+
private void SendProjectBasedTelemetry(ProjectLaunchSettingsModel? launchSettings)
824+
{
825+
Debug.Assert(ProjectFileFullPath != null);
826+
var projectIdentifier = RunTelemetry.GetProjectBasedIdentifier(ProjectFileFullPath, GetRepositoryRoot(), Sha256Hasher.Hash);
827+
828+
// Get package and project reference counts for project-based apps
829+
int packageReferenceCount = 0;
830+
int projectReferenceCount = 0;
831+
832+
// Try to get project information for telemetry if we built the project
833+
if (ShouldBuild)
834+
{
835+
try
836+
{
837+
var globalProperties = MSBuildArgs.GlobalProperties?.ToDictionary() ?? new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
838+
globalProperties[Constants.EnableDefaultItems] = "false";
839+
globalProperties[Constants.MSBuildExtensionsPath] = AppContext.BaseDirectory;
840+
841+
using var collection = new ProjectCollection(globalProperties: globalProperties);
842+
var project = collection.LoadProject(ProjectFileFullPath).CreateProjectInstance();
843+
844+
packageReferenceCount = RunTelemetry.CountPackageReferences(project);
845+
projectReferenceCount = RunTelemetry.CountProjectReferences(project);
846+
}
847+
catch
848+
{
849+
// If project evaluation fails for telemetry, use defaults
850+
// We don't want telemetry collection to affect the run operation
851+
}
852+
}
853+
854+
RunTelemetry.TrackRunEvent(
855+
isFileBased: false,
856+
projectIdentifier: projectIdentifier,
857+
launchProfile: LaunchProfile,
858+
noLaunchProfile: NoLaunchProfile,
859+
launchSettings: launchSettings,
860+
packageReferenceCount: packageReferenceCount,
861+
projectReferenceCount: projectReferenceCount);
862+
}
863+
864+
/// <summary>
865+
/// Attempts to find the repository root directory.
866+
/// </summary>
867+
/// <returns>Repository root path if found, null otherwise</returns>
868+
private string? GetRepositoryRoot()
869+
{
870+
try
871+
{
872+
var currentDir = ProjectFileFullPath != null
873+
? Path.GetDirectoryName(ProjectFileFullPath)
874+
: Directory.GetCurrentDirectory();
875+
876+
while (currentDir != null)
877+
{
878+
if (Directory.Exists(Path.Combine(currentDir, ".git")))
879+
{
880+
return currentDir;
881+
}
882+
currentDir = Directory.GetParent(currentDir)?.FullName;
883+
}
884+
}
885+
catch
886+
{
887+
// Ignore errors when trying to find repo root
888+
}
889+
890+
return null;
891+
}
756892
}

0 commit comments

Comments
 (0)