Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a01066c

Browse files
[release/10.0.1xx] Source code updates from dotnet/sdk (#3283)
[release/10.0.1xx] Source code updates from dotnet/sdk
1 parent 45832e2 commit a01066c

File tree

10 files changed

+356
-332
lines changed

10 files changed

+356
-332
lines changed

src/sdk/NuGet.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<clear />
55
<!--Begin: Package sources managed by Dependency Flow automation. Do not edit the sources below.-->
66
<!-- Begin: Package sources from dotnet-dotnet -->
7-
<add key="darc-pub-dotnet-dotnet-79c85d9" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-dotnet-79c85d96/nuget/v3/index.json" />
7+
<add key="darc-pub-dotnet-dotnet-50d7970" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-dotnet-50d79701/nuget/v3/index.json" />
88
<!-- End: Package sources from dotnet-dotnet -->
99
<!-- Begin: Package sources from microsoft-testfx -->
1010
<!-- End: Package sources from microsoft-testfx -->

src/sdk/documentation/general/dotnet-run-file.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ Additionally, the implicit project file has the following customizations:
5656
in case there is a project or solution in the same directory as the file-based app.
5757
This ensures that items from nested projects and artifacts are not included by the app.
5858

59+
- `EnableDefaultEmbeddedResourceItems` and `EnableDefaultNoneItems` properties are set to `false` if the default SDK (`Microsoft.NET.Sdk`) is being used.
60+
This avoids including files like `./**/*.resx` in simple file-based apps where users usually don't expect that.
61+
5962
## Grow up
6063

6164
When file-based programs reach an inflection point where build customizations in a project file are needed,

src/sdk/eng/Version.Details.props

Lines changed: 71 additions & 71 deletions
Large diffs are not rendered by default.

src/sdk/eng/Version.Details.xml

Lines changed: 204 additions & 204 deletions
Large diffs are not rendered by default.

src/sdk/eng/dotnet-format/dotnet-format-integration.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,6 @@ parameters:
5050
_branchName: "main"
5151
_sha: "1b2ff365399ab6736a9ea4c98ab1b60acda5d917"
5252
_useParentSdk: 0
53-
- Name: razor_tooling
54-
_repo: "https://github.com/dotnet/razor"
55-
_repoName: "dotnet/razor"
56-
_targetSolution: "Razor.sln"
57-
_branchName: "main"
58-
_sha: "ecb4b595e3322a18c240f50a763868540f51eaaa"
59-
_useParentSdk: 0
6053

6154
- name: timeoutInMinutes
6255
type: number

src/sdk/global.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"errorMessage": "The .NET SDK is not installed or is not configured correctly. Please run ./build to install the correct SDK version locally."
88
},
99
"tools": {
10-
"dotnet": "10.0.100-rc.1.25451.107",
10+
"dotnet": "10.0.100-rc.2.25502.107",
1111
"runtimes": {
1212
"dotnet": [
1313
"$(MicrosoftNETCorePlatformsPackageVersion)"
@@ -21,8 +21,8 @@
2121
}
2222
},
2323
"msbuild-sdks": {
24-
"Microsoft.DotNet.Arcade.Sdk": "10.0.0-beta.25515.111",
25-
"Microsoft.DotNet.Helix.Sdk": "10.0.0-beta.25515.111",
24+
"Microsoft.DotNet.Arcade.Sdk": "10.0.0-beta.25520.117",
25+
"Microsoft.DotNet.Helix.Sdk": "10.0.0-beta.25520.117",
2626
"Microsoft.Build.NoTargets": "3.7.0",
2727
"Microsoft.Build.Traversal": "3.4.0",
2828
"Microsoft.WixToolset.Sdk": "5.0.2-dotnet.2811440"

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,7 @@ public static void WriteProjectFile(
11561156
var packageDirectives = directives.OfType<CSharpDirective.Package>();
11571157
var projectDirectives = directives.OfType<CSharpDirective.Project>();
11581158

1159+
const string defaultSdkName = "Microsoft.NET.Sdk";
11591160
string firstSdkName;
11601161
string? firstSdkVersion;
11611162

@@ -1167,7 +1168,7 @@ public static void WriteProjectFile(
11671168
}
11681169
else
11691170
{
1170-
firstSdkName = "Microsoft.NET.Sdk";
1171+
firstSdkName = defaultSdkName;
11711172
firstSdkVersion = null;
11721173
}
11731174

@@ -1191,6 +1192,18 @@ public static void WriteProjectFile(
11911192
<DisableDefaultItemsInProjectFolder>true</DisableDefaultItemsInProjectFolder>
11921193
""");
11931194

1195+
// Only set these to false when using the default SDK with no additional SDKs
1196+
// to avoid including .resx and other files that are typically not expected in simple file-based apps.
1197+
// When other SDKs are used (e.g., Microsoft.NET.Sdk.Web), keep the default behavior.
1198+
bool usingOnlyDefaultSdk = firstSdkName == defaultSdkName && sdkDirectives.Count() <= 1;
1199+
if (usingOnlyDefaultSdk)
1200+
{
1201+
writer.WriteLine($"""
1202+
<EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
1203+
<EnableDefaultNoneItems>false</EnableDefaultNoneItems>
1204+
""");
1205+
}
1206+
11941207
// Write default properties before importing SDKs so they can be overridden by SDKs
11951208
// (and implicit build files which are imported by the default .NET SDK).
11961209
foreach (var (name, value) in DefaultProperties)
@@ -1399,9 +1412,9 @@ public static void WriteProjectFile(
13991412

14001413
if (!sdkDirectives.Any())
14011414
{
1402-
Debug.Assert(firstSdkName == "Microsoft.NET.Sdk" && firstSdkVersion == null);
1403-
writer.WriteLine("""
1404-
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
1415+
Debug.Assert(firstSdkName == defaultSdkName && firstSdkVersion == null);
1416+
writer.WriteLine($"""
1417+
<Import Project="Sdk.targets" Sdk="{defaultSdkName}" />
14051418
""");
14061419
}
14071420

src/sdk/test/dotnet.Tests/CommandTests/Project/Convert/DotnetProjectConvertTests.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,14 @@ public void NestedDirectory()
394394
}
395395

396396
/// <summary>
397-
/// Default items like <c>None</c> or <c>Content</c> are copied over.
397+
/// Default items like <c>None</c> or <c>Content</c> are copied over if non-default SDK is used.
398398
/// </summary>
399399
[Fact]
400-
public void DefaultItems()
400+
public void DefaultItems_NonDefaultSdk()
401401
{
402402
var testInstance = _testAssetsManager.CreateTestDirectory();
403403
File.WriteAllText(Path.Join(testInstance.Path, "Program.cs"), """
404+
#:sdk Microsoft.NET.Sdk.Web
404405
Console.WriteLine();
405406
""");
406407
File.WriteAllText(Path.Join(testInstance.Path, "my.json"), "");
@@ -433,6 +434,8 @@ public void DefaultItems_MoreIncluded()
433434
var testInstance = _testAssetsManager.CreateTestDirectory();
434435
File.WriteAllText(Path.Join(testInstance.Path, "Program.cs"), """
435436
#:property EnableDefaultCompileItems=true
437+
#:property EnableDefaultEmbeddedResourceItems=true
438+
#:property EnableDefaultNoneItems=true
436439
Console.WriteLine();
437440
""");
438441
File.WriteAllText(Path.Join(testInstance.Path, "my.json"), "");
@@ -487,6 +490,8 @@ public void DefaultItems_ExcludedViaMetadata()
487490
{
488491
var testInstance = _testAssetsManager.CreateTestDirectory();
489492
File.WriteAllText(Path.Join(testInstance.Path, "Program.cs"), """
493+
#:property EnableDefaultEmbeddedResourceItems=true
494+
#:property EnableDefaultNoneItems=true
490495
Console.WriteLine();
491496
""");
492497
File.WriteAllText(Path.Join(testInstance.Path, "my.json"), "");
@@ -522,6 +527,7 @@ public void DefaultItems_ImplicitBuildFileInDirectory()
522527
{
523528
var testInstance = _testAssetsManager.CreateTestDirectory();
524529
File.WriteAllText(Path.Join(testInstance.Path, "Program.cs"), """
530+
#:sdk Microsoft.NET.Sdk.Web
525531
Console.WriteLine(Util.GetText());
526532
""");
527533
File.WriteAllText(Path.Join(testInstance.Path, "Util.cs"), """
@@ -677,6 +683,8 @@ public void DefaultItems_AlongsideProj([CombinatorialValues("sln", "slnx", "cspr
677683

678684
var testInstance = _testAssetsManager.CreateTestDirectory();
679685
File.WriteAllText(Path.Join(testInstance.Path, "Program.cs"), """
686+
#:property EnableDefaultEmbeddedResourceItems=true
687+
#:property EnableDefaultNoneItems=true
680688
Console.WriteLine();
681689
""");
682690
File.WriteAllText(Path.Join(testInstance.Path, "my.json"), "");

src/sdk/test/dotnet.Tests/CommandTests/Run/RunFileTests.cs

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,7 @@ public void Verbosity_CompilationDiagnostics()
13631363
}
13641364

13651365
/// <summary>
1366-
/// Default projects include embedded resources by default.
1366+
/// File-based projects using the default SDK do not include embedded resources by default.
13671367
/// </summary>
13681368
[Fact]
13691369
public void EmbeddedResource()
@@ -1372,6 +1372,21 @@ public void EmbeddedResource()
13721372
File.WriteAllText(Path.Join(testInstance.Path, "Program.cs"), s_programReadingEmbeddedResource);
13731373
File.WriteAllText(Path.Join(testInstance.Path, "Resources.resx"), s_resx);
13741374

1375+
// By default, with the default SDK, embedded resources are not included.
1376+
new DotnetCommand(Log, "run", "Program.cs")
1377+
.WithWorkingDirectory(testInstance.Path)
1378+
.Execute()
1379+
.Should().Pass()
1380+
.And.HaveStdOut("""
1381+
Resource not found
1382+
""");
1383+
1384+
// This behavior can be overridden to enable embedded resources.
1385+
File.WriteAllText(Path.Join(testInstance.Path, "Program.cs"), $"""
1386+
#:property EnableDefaultEmbeddedResourceItems=true
1387+
{s_programReadingEmbeddedResource}
1388+
""");
1389+
13751390
new DotnetCommand(Log, "run", "Program.cs")
13761391
.WithWorkingDirectory(testInstance.Path)
13771392
.Execute()
@@ -1380,9 +1395,23 @@ public void EmbeddedResource()
13801395
[MyString, TestValue]
13811396
""");
13821397

1383-
// This behavior can be overridden.
1398+
// When using a non-default SDK, embedded resources are included by default.
13841399
File.WriteAllText(Path.Join(testInstance.Path, "Program.cs"), $"""
1385-
#:property EnableDefaultEmbeddedResourceItems=false
1400+
#:sdk Microsoft.NET.Sdk.Web
1401+
{s_programReadingEmbeddedResource}
1402+
""");
1403+
1404+
new DotnetCommand(Log, "run", "Program.cs")
1405+
.WithWorkingDirectory(testInstance.Path)
1406+
.Execute()
1407+
.Should().Pass()
1408+
.And.HaveStdOut("""
1409+
[MyString, TestValue]
1410+
""");
1411+
1412+
// When using the default SDK explicitly, embedded resources are not included.
1413+
File.WriteAllText(Path.Join(testInstance.Path, "Program.cs"), $"""
1414+
#:sdk Microsoft.NET.Sdk
13861415
{s_programReadingEmbeddedResource}
13871416
""");
13881417

@@ -1405,7 +1434,10 @@ public void EmbeddedResource_AlongsideProj([CombinatorialValues("sln", "slnx", "
14051434
bool considered = ext is "sln" or "slnx" or "csproj";
14061435

14071436
var testInstance = _testAssetsManager.CreateTestDirectory();
1408-
File.WriteAllText(Path.Join(testInstance.Path, "Program.cs"), s_programReadingEmbeddedResource);
1437+
File.WriteAllText(Path.Join(testInstance.Path, "Program.cs"), $"""
1438+
#:property EnableDefaultEmbeddedResourceItems=true
1439+
{s_programReadingEmbeddedResource}
1440+
""");
14091441
File.WriteAllText(Path.Join(testInstance.Path, "Resources.resx"), s_resx);
14101442
File.WriteAllText(Path.Join(testInstance.Path, $"repo.{ext}"), "");
14111443

@@ -3147,6 +3179,7 @@ public void UpToDate_DefaultItems(bool optOut)
31473179
var testInstance = _testAssetsManager.CreateTestDirectory();
31483180
var code = $"""
31493181
{(optOut ? "#:property FileBasedProgramCanSkipMSBuild=false" : "")}
3182+
#:property EnableDefaultEmbeddedResourceItems=true
31503183
{s_programReadingEmbeddedResource}
31513184
""";
31523185
File.WriteAllText(Path.Join(testInstance.Path, "Program.cs"), code);
@@ -3167,50 +3200,20 @@ public void UpToDate_DefaultItems(bool optOut)
31673200
Build(testInstance, BuildLevel.All, ["--no-cache"], expectedOutput: "[MyString, UpdatedValue]");
31683201
}
31693202

3170-
/// <summary>
3171-
/// Combination of <see cref="UpToDate_DefaultItems"/> with <see cref="CscOnly"/> optimization.
3172-
/// </summary>
3173-
[Theory, CombinatorialData] // https://github.com/dotnet/sdk/issues/50912
3174-
public void UpToDate_DefaultItems_CscOnly(bool optOut)
3175-
{
3176-
var testInstance = _testAssetsManager.CreateTestDirectory(baseDirectory: OutOfTreeBaseDirectory);
3177-
var code = $"""
3178-
{(optOut ? "#:property FileBasedProgramCanSkipMSBuild=false" : "")}
3179-
{s_programReadingEmbeddedResource}
3180-
""";
3181-
File.WriteAllText(Path.Join(testInstance.Path, "Program.cs"), code);
3182-
File.WriteAllText(Path.Join(testInstance.Path, "Resources.resx"), s_resx);
3183-
3184-
Build(testInstance, optOut ? BuildLevel.All : BuildLevel.Csc, expectedOutput: optOut ? "[MyString, TestValue]" : "Resource not found");
3185-
3186-
// Update the RESX file.
3187-
File.WriteAllText(Path.Join(testInstance.Path, "Resources.resx"), s_resx.Replace("TestValue", "UpdatedValue"));
3188-
3189-
Build(testInstance, optOut ? BuildLevel.All : BuildLevel.None, expectedOutput: optOut ? "[MyString, UpdatedValue]" : "Resource not found");
3190-
3191-
// Update the C# file.
3192-
File.WriteAllText(Path.Join(testInstance.Path, "Program.cs"), "//v2\n" + code);
3193-
3194-
Build(testInstance, optOut ? BuildLevel.All : BuildLevel.Csc, expectedOutput: optOut ? "[MyString, UpdatedValue]" : "Resource not found");
3195-
3196-
Build(testInstance, BuildLevel.All, ["--no-cache"], expectedOutput: "[MyString, UpdatedValue]");
3197-
3198-
// Update the C# file.
3199-
File.WriteAllText(Path.Join(testInstance.Path, "Program.cs"), "//v3\n" + code);
3200-
3201-
Build(testInstance, optOut ? BuildLevel.All : BuildLevel.Csc, expectedOutput: "[MyString, UpdatedValue]");
3202-
}
3203-
32043203
/// <summary>
32053204
/// Combination of <see cref="UpToDate_DefaultItems"/> with <see cref="CscOnly_AfterMSBuild"/> optimization.
32063205
/// </summary>
3206+
/// <remarks>
3207+
/// Note: we cannot test <see cref="CscOnly"/> because that optimization doesn't support neither <c>#:property</c> nor <c>#:sdk</c> which we need to enable default items.
3208+
/// </remarks>
32073209
[Theory, CombinatorialData] // https://github.com/dotnet/sdk/issues/50912
32083210
public void UpToDate_DefaultItems_CscOnly_AfterMSBuild(bool optOut)
32093211
{
32103212
var testInstance = _testAssetsManager.CreateTestDirectory(baseDirectory: OutOfTreeBaseDirectory);
32113213
var code = $"""
32123214
#:property Configuration=Release
32133215
{(optOut ? "#:property FileBasedProgramCanSkipMSBuild=false" : "")}
3216+
#:property EnableDefaultEmbeddedResourceItems=true
32143217
{s_programReadingEmbeddedResource}
32153218
""";
32163219
File.WriteAllText(Path.Join(testInstance.Path, "Program.cs"), code);
@@ -3861,6 +3864,8 @@ public void Api_Diagnostic_01()
38613864
<FileBasedProgram>true</FileBasedProgram>
38623865
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
38633866
<DisableDefaultItemsInProjectFolder>true</DisableDefaultItemsInProjectFolder>
3867+
<EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
3868+
<EnableDefaultNoneItems>false</EnableDefaultNoneItems>
38643869
<OutputType>Exe</OutputType>
38653870
<TargetFramework>{ToolsetInfo.CurrentTargetFramework}</TargetFramework>
38663871
<ImplicitUsings>enable</ImplicitUsings>
@@ -3929,6 +3934,8 @@ public void Api_Diagnostic_02()
39293934
<FileBasedProgram>true</FileBasedProgram>
39303935
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
39313936
<DisableDefaultItemsInProjectFolder>true</DisableDefaultItemsInProjectFolder>
3937+
<EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
3938+
<EnableDefaultNoneItems>false</EnableDefaultNoneItems>
39323939
<OutputType>Exe</OutputType>
39333940
<TargetFramework>{ToolsetInfo.CurrentTargetFramework}</TargetFramework>
39343941
<ImplicitUsings>enable</ImplicitUsings>

src/source-manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@
9191
"commitSha": "082359066ee0064039b9b1f1f025bdd0507d06de"
9292
},
9393
{
94-
"barId": 289304,
94+
"barId": 290036,
9595
"path": "sdk",
9696
"remoteUri": "https://github.com/dotnet/sdk",
97-
"commitSha": "ce50bec288464cb6b122f137bc68b4661e942851"
97+
"commitSha": "17d3f8b5738948586d991f6b5e00265cd499cadb"
9898
},
9999
{
100100
"barId": 289818,

0 commit comments

Comments
 (0)