-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Today, dotnet run file.cs
picks up implicit build files from the surrounding environment. This means that anywhere in the context of an existing .NET repo, I cannot make a simple script to perform a refactoring or automate build processes without the Directory.Build.props/targets/packages
for that repo getting pulled in automatically, which is usually undesirable in these types of scripts. #49808 allows working around this by using --file
; while this will be needed for running .cs
files in the same directory as a .csproj
file for backcompat, it should not be necessary to pass --file
when in a directory that does not have a project file in it. Consider, for example, replacing https://github.com/dotnet/roslyn/blob/main/eng/generate-compiler-code.ps1 with a .cs script. dotnet run file.cs
in this directory could never have succeeded before the new feature, as there is no project in this directory. Yet, dotnet run file.cs
also doesn't work in 10p5 or p6, because the implicit project files from this directory and parent directories are picked up.
Practically speaking, I expect most of my usage of dotnet run file.cs
to be in 3 types of scenarios:
- Confirming behavior of snippets of C# code. These types of things can be thrown in a clean directory in
/tmp
and are unaffected by this issue. - Temporary scripts to do refactorings/reorganizations of code, files, or other similar scenarios. I expect most of these to happen inside repositories that are already .NET repositories, so picking up implicit build files is going to negatively impact my ability to use them here.
- Replacing build scripts with
.cs
files; these also should not pick up on the implicit build files in my directory. They automate the rest of the build process, they don't need to pull in the nuget packages the actual app depends on and such.
Related to #49790.