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
+8-3Lines changed: 8 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -163,14 +163,16 @@ They are not cleaned immediately because they can be re-used on subsequent runs
163
163
164
164
It is possible to specify some project metadata via *file-level directives*
165
165
which are [ignored][ignored-directives] by the C# language but recognized by the SDK CLI.
166
-
Directives `sdk`, `package`, and `property` are translated into `<Project Sdk="...">`, `<PackageReference>`, and `<Property>` project elements, respectively.
166
+
Directives `sdk`, `package`, `property`, and `project` are translated into
167
+
`<Project Sdk="...">`, `<PackageReference>`, `<PropertyGroup>`, and `<ProjectReference>` project elements, respectively.
167
168
Other directives result in an error, reserving them for future use.
The value must be separated from the kind (`package`/`sdk`/`property`) of the directive by whitespace
@@ -184,6 +186,9 @@ The value of `#:property` is split by the separator and injected as `<{0}>{1}</{
184
186
It is an error if no separator appears in the value or if the first part (property name) is empty (the property value is allowed to be empty) or contains invalid characters.
185
187
The value of `#:package` is split by the separator and injected as `<PackageReference Include="{0}" Version="{1}">` (or without the `Version` attribute if there is no separator) in an `<ItemGroup>`.
186
188
It is an error if the first part (package name) is empty (the package version is allowed to be empty, but that results in empty `Version=""`).
189
+
The value of `#:project` is injected as `<ProjectReference Include="{0}" />` in an `<ItemGroup>`.
190
+
If the value points to an existing directory, a project file is found inside that directory and its path is used instead
191
+
(because `ProjectReference` items don't support directory paths).
187
192
188
193
Because these directives are limited by the C# language to only appear before the first "C# token" and any `#if`,
189
194
dotnet CLI can look for them via a regex or Roslyn lexer without any knowledge of defined conditional symbols
@@ -330,8 +335,8 @@ We could also add `dotnet compile` command that would be the equivalent of `dotn
330
335
e.g., via `dotnet clean --file-based-program <path-to-entry-point>`
331
336
or `dotnet clean --all-file-based-programs`.
332
337
333
-
Adding package references via `dotnet package add` could be supported for file-based programs as well,
334
-
i.e., the command would add a `#:package` directive to the top of a `.cs` file.
338
+
Adding references via `dotnet package add`/`dotnet reference add` could be supported for file-based programs as well,
339
+
i.e., the command would add a `#:package`/`#:project` directive to the top of a `.cs` file.
0 commit comments