diff --git a/crates/cli/src/tasks/csharp.rs b/crates/cli/src/tasks/csharp.rs index ed2f46b002..472e26bc50 100644 --- a/crates/cli/src/tasks/csharp.rs +++ b/crates/cli/src/tasks/csharp.rs @@ -1,33 +1,43 @@ -use duct::cmd; -use std::path::{Path, PathBuf}; - -pub(crate) fn build_csharp(project_path: &Path, _build_debug: bool) -> anyhow::Result { - // NOTE: wasi.sdk does not currently optimize release - - let output_path = project_path.join("bin/Release/net7.0/StdbModule.wasm"); - - // delete existing wasm file if exists - if output_path.exists() { - std::fs::remove_file(&output_path)?; - } - - // run dotnet publish using cmd macro - let result = cmd!("dotnet", "publish", "-c", "Release").dir(project_path).run(); - match result { - Ok(_) => {} - Err(error) => { - if error.kind() == std::io::ErrorKind::NotFound { - anyhow::bail!("Failed to build project. dotnet not found in path. Please install the .NET Core SDK."); - } else { - anyhow::bail!("Failed to build project. {}", error); - } - } - } - - // check if file exists - if !output_path.exists() { - anyhow::bail!("Failed to build project"); - } - - Ok(output_path) -} +use anyhow::Context; +use duct::cmd; +use std::fs; +use std::path::{Path, PathBuf}; + +pub(crate) fn build_csharp(project_path: &Path, _build_debug: bool) -> anyhow::Result { + // NOTE: wasi.sdk does not currently optimize release + + let output_path = project_path.join("bin/Release/net7.0/StdbModule.wasm"); + + // delete existing wasm file if exists + if output_path.exists() { + std::fs::remove_file(&output_path)?; + } + + // Ensure the project path exists. + fs::metadata(project_path).with_context(|| { + format!( + "The provided project path '{}' does not exist.", + project_path.to_str().unwrap() + ) + })?; + + // run dotnet publish using cmd macro + let result = cmd!("dotnet", "publish", "-c", "Release").dir(project_path).run(); + match result { + Ok(_) => {} + Err(error) => { + if error.kind() == std::io::ErrorKind::NotFound { + anyhow::bail!("Failed to build project. dotnet not found in path. Please install the .NET Core SDK."); + } else { + anyhow::bail!("Failed to build project. {}", error); + } + } + } + + // check if file exists + if !output_path.exists() { + anyhow::bail!("Failed to build project"); + } + + Ok(output_path) +}