You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/general/dotnet-run-file.md
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -248,6 +248,16 @@ The directives are processed as follows:
248
248
(because `ProjectReference` items don't support directory paths).
249
249
An error is reported if zero or more than one projects are found in the directory, just like `dotnet reference add` would do.
250
250
251
+
Directive values support MSBuild variables (like `$(..)`) normally as they are translated literally and left to MSBuild engine to process.
252
+
However, in `#:project` directives, variables might not be preserved during [grow up](#grow-up),
253
+
because there is additional processing of those directives that makes it technically challenging to preserve variables in all cases
254
+
(project directive values need to be resolved to be relative to the target directory
255
+
and also to point to a project file rather than a directory).
256
+
Note that it is not expected that variables inside the path change their meaning during the conversion,
257
+
so for example `#:project ../$(LibName)` is translated to `<ProjectReference Include="../../$(LibName)/Lib.csproj" />` (i.e., the variable is preserved).
258
+
However, variables at the start can change, so for example `#:project $(ProjectDir)../Lib` is translated to `<ProjectReference Include="../../Lib/Lib.csproj" />` (i.e., the variable is expanded).
259
+
In other directives, all variables are preserved during conversion.
260
+
251
261
Because these directives are limited by the C# language to only appear before the first "C# token" and any `#if`,
252
262
dotnet CLI can look for them via a regex or Roslyn lexer without any knowledge of defined conditional symbols
253
263
and can do that efficiently by stopping the search when it sees the first "C# token".
Copy file name to clipboardExpand all lines: src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs
+97-17Lines changed: 97 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -6,12 +6,14 @@
6
6
usingSystem.Collections.Generic;
7
7
usingSystem.Collections.Immutable;
8
8
usingSystem.Diagnostics;
9
+
usingSystem.Diagnostics.CodeAnalysis;
9
10
usingSystem.IO;
10
11
usingSystem.Linq;
11
12
usingSystem.Text;
12
13
usingSystem.Text.Json.Serialization;
13
14
usingSystem.Text.RegularExpressions;
14
15
usingSystem.Xml;
16
+
usingMicrosoft.Build.Execution;
15
17
usingMicrosoft.CodeAnalysis;
16
18
usingMicrosoft.CodeAnalysis.CSharp;
17
19
usingMicrosoft.CodeAnalysis.CSharp.Syntax;
@@ -225,6 +227,30 @@ static bool Fill(ref WhiteSpaceInfo info, in SyntaxTriviaList triviaList, int in
225
227
}
226
228
}
227
229
}
230
+
231
+
/// <summary>
232
+
/// If there are any <c>#:project</c> <paramref name="directives"/>, expands <c>$()</c> in them and ensures they point to project files (not directories).
// https://github.com/dotnet/sdk/issues/51487: Delete copies of methods from MsbuildProject and MSBuildUtilities from the source package, sharing the original method(s) under src/Cli instead.
0 commit comments