diff --git a/crates/cli/src/subcommands/generate.rs b/crates/cli/src/subcommands/generate.rs index c090baa046a..5f6d935bfc5 100644 --- a/crates/cli/src/subcommands/generate.rs +++ b/crates/cli/src/subcommands/generate.rs @@ -252,7 +252,7 @@ pub async fn exec_ex( } } - if let Err(err) = lang.format_files(paths) { + if let Err(err) = lang.format_files(out_dir, paths) { // If we couldn't format the files, print a warning but don't fail the entire // task as the output should still be usable, just less pretty. eprintln!("Could not format generated files: {err}"); @@ -285,10 +285,10 @@ impl clap::ValueEnum for Language { } impl Language { - fn format_files(&self, generated_files: BTreeSet) -> anyhow::Result<()> { + fn format_files(&self, project_dir: &PathBuf, generated_files: BTreeSet) -> anyhow::Result<()> { match self { Language::Rust => rustfmt(generated_files)?, - Language::Csharp => dotnet_format(generated_files)?, + Language::Csharp => dotnet_format(project_dir, generated_files)?, Language::TypeScript => { // TODO: implement formatting. } diff --git a/crates/cli/src/tasks/csharp.rs b/crates/cli/src/tasks/csharp.rs index 349bdfcd1bd..8a18f8ed55a 100644 --- a/crates/cli/src/tasks/csharp.rs +++ b/crates/cli/src/tasks/csharp.rs @@ -108,7 +108,7 @@ pub(crate) fn build_csharp(project_path: &Path, build_debug: bool) -> anyhow::Re anyhow::bail!("Built project successfully but couldn't find the output file."); } -pub(crate) fn dotnet_format(files: impl IntoIterator) -> anyhow::Result<()> { +pub(crate) fn dotnet_format(project_dir: &PathBuf, files: impl IntoIterator) -> anyhow::Result<()> { duct::cmd( "dotnet", itertools::chain( @@ -128,6 +128,8 @@ pub(crate) fn dotnet_format(files: impl IntoIterator) -> anyhow: files.into_iter().map_into(), ), ) + // This is important because we're running with `--folder`. We want to format the right folder! + .dir(project_dir) .run()?; Ok(()) }