Skip to content

dotnet run file.cs should not pick up implicit build files by default #49826

@333fred

Description

@333fred

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:

  1. 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.
  2. 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.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-run-fileItems related to the "dotnet run <file>" effort

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions