(project_path: &Path, build_debug: bool)
| 9 | } |
| 10 | |
| 11 | pub(crate) fn build_csharp(project_path: &Path, build_debug: bool) -> anyhow::Result<PathBuf> { |
| 12 | // All `dotnet` commands must execute in the project directory, otherwise |
| 13 | // global.json won't have any effect and wrong .NET SDK might be picked. |
| 14 | macro_rules! dotnet { |
| 15 | ($($arg:expr),*) => { |
| 16 | duct::cmd!("dotnet", $($arg),*).dir(project_path) |
| 17 | }; |
| 18 | } |
| 19 | |
| 20 | // Check if the `wasi-experimental` workload is installed. Unfortunately, we |
| 21 | // have to do this by inspecting the human-readable output. There is a |
| 22 | // hidden `--machine-readable` flag but it also mixes in human-readable |
| 23 | // output as well as unnecessarily updates various unrelated manifests. |
| 24 | match dotnet!("workload", "list").read() { |
| 25 | Ok(workloads) if workloads.contains("wasi-experimental") => {} |
| 26 | Ok(_) => { |
| 27 | // If wasi-experimental is not found, first check if we're running |
| 28 | // on .NET SDK 8.0. We can't even install that workload on older |
| 29 | // versions, and we don't support .NET 9.0 yet, so this helps to |
| 30 | // provide a nicer message than "Workload ID wasi-experimental is not recognized.". |
| 31 | let version = dotnet!("--version").read().unwrap_or_default(); |
| 32 | if parse_major_version(&version) != Some(8) { |
| 33 | anyhow::bail!(concat!( |
| 34 | ".NET SDK 8.0 is required, but found {version}.\n", |
| 35 | "If you have multiple versions of .NET SDK installed, configure your project using https://learn.microsoft.com/en-us/dotnet/core/tools/global-json." |
| 36 | )); |
| 37 | } |
| 38 | |
| 39 | // Finally, try to install the workload ourselves. On some systems |
| 40 | // this might require elevated privileges, so print a nice error |
| 41 | // message if it fails. |
| 42 | dotnet!( |
| 43 | "workload", |
| 44 | "install", |
| 45 | "wasi-experimental", |
| 46 | "--skip-manifest-update" |
| 47 | ) |
| 48 | .stderr_capture() |
| 49 | .run() |
| 50 | .context(concat!( |
| 51 | "Couldn't install the required wasi-experimental workload.\n", |
| 52 | "You might need to install it manually by running `dotnet workload install wasi-experimental` with privileged rights." |
| 53 | ))?; |
| 54 | } |
| 55 | Err(error) if error.kind() == std::io::ErrorKind::NotFound => { |
| 56 | anyhow::bail!("dotnet not found in PATH. Please install .NET SDK 8.0.") |
| 57 | } |
| 58 | Err(error) => anyhow::bail!("{error}"), |
| 59 | }; |
| 60 | |
| 61 | let config_name = if build_debug { "Debug" } else { "Release" }; |
| 62 | |
| 63 | // Ensure the project path exists. |
| 64 | fs::metadata(project_path).with_context(|| { |
| 65 | format!( |
| 66 | "The provided project path '{}' does not exist.", |
| 67 | project_path.to_str().unwrap() |
| 68 | ) |
no test coverage detected
searching dependent graphs…