dotnet / dotnet/sdk

"dotnet restore" and "dotnet publish" use relative BaseIntermediateOutputPath even if it's set to absolute path

Open
#46,990 3 comments 0 reactions 1 assignee Claimed by @edvilme View on GitHub
Area-NetSDK untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### Describe the bug
"dotnet restore" and "dotnet publish" use relative `BaseIntermediateOutputPath` even if it's set to absolute path (or `$(SolutionDir)` gets lost in the process somewhere).
It's possible that `--artifacts-path` is ignored as well. I have tried setting it explicitly, as well as `/p:ArtifactsPath` and `...` in `Directory.Build.props`, but same result.

### To Reproduce

1. Create an empty solution
2. Add a .NET 8 GUI app project to it (into a subdirectory, i.e. `src//`)
3. Add a Directory.Build.props to the root solution directory with the following contents:
```xml


1701;1702;2087;2091
false
en-US
false
false
$(SolutionDir)build\intermediate\$(MSBuildProjectName)\
$(SolutionDir)build\staging\bin\$(MSBuildProjectName)\$(Configuration)-$(Platform)\

```
4. Add this to the .csproj of the created project:
```xml


WinExe
true

false
win-x64
true
true
true
true
true
false
false

false
true
true






```
5. Run project build via Visual Studio
6. The intermediate files (and directories) will be created in the project directory and not in `BaseIntermediateOutputPath` (`$(SolutionDir)build\intermediate\$(MSBuildProjectName)\`), though the hirerarchy will match except for `$(SolutionDir)` (almost as if it's ignored/evaluated to "")
7. The `dotnet publish` command will later fail with `Root assembly 'build\intermediate\\\.dll' could not be found`

### Exceptions (if any)

Not exceptions, but errors during publishing (see build log below).

### Further technical details
- `dotnet --info`:
```
.NET SDK:
Version: 9.0.102
Commit: cb83cd4923
Workload version: 9.0.100-manifests.4a54b1a6
MSBuild version: 17.12.18+ed8c6aec5

Runtime Environment:
OS Name: Windows
OS Version: 10.0.22631
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.102\

.NET workloads installed:
[wasm-tools]
Installation Source: VS 17.12.35707.178
Manifest Version: 9.0.1/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.workload.mono.toolchain.current\9.0.1\WorkloadManifest.json
Install Type: Msi

[android]
Installation Source: VS 17.12.35707.178
Manifest Version: 35.0.7/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.android\35.0.7\WorkloadManifest.json
Install Type: Msi

[ios]
Installation Source: VS 17.12.35707.178
Manifest Version: 18.1.9163/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.ios\18.1.9163\WorkloadManifest.json
Install Type: Msi

[maui-windows]
Installation Source: VS 17.12.35707.178
Manifest Version: 9.0.14/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.maui\9.0.14\WorkloadManifest.json
Install Type: Msi

[maccatalyst]
Installation Source: VS 17.12.35707.178
Manifest Version: 18.1.9163/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.maccatalyst\18.1.9163\WorkloadManifest.json
Install Type: Msi

Configured to use loose manifests when installing new manifests.

Host:
Version: 9.0.1
Architecture: x64
Commit: c8acea2262

.NET SDKs installed:
9.0.102 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

global.json file:
Not found
```

- IDE: Visual Studio 2022 (17.12.4)

- Build log with errors:
```
1>------ Build started: Project: , Configuration: x64 ------
1> -> \build\staging\bin\\-x64\.dll
1>ProjectDir: \src\\
1>BaseIntermediateOutputPath: \build\intermediate\\
1> Determining projects to restore...
1> Restored \src\\.csproj (in 199 ms).
1> Optimizing assemblies for size. This process might take a while.
1>ILLink : error IL1032: Root assembly 'build\intermediate\\\.dll' could not be found. [\src\\.csproj]
1>E:\PackageCache\NuGet\microsoft.net.illink.tasks\8.0.12\build\Microsoft.NET.ILLink.targets(87,5): error NETSDK1144: Optimizing assemblies for size failed. [\src\\.csproj]
1>
1>Workload updates are available. Run `dotnet workload list` for more information.
1>\src\Runtime\HostApp\Loader\\.csproj(37,3): error MSB3073: The command "dotnet publish \src\\.csproj -r win-x64 -c Internal_LocalDev --disable-build-servers --no-build -o \build\out\\-x64\win\" exited with code 1.
1>Done building project ".csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
```

- Intermediate files after `dotnet restore` ending up in project's directory instead of in `BaseIntermediateOutputPath`:

![Image](https://github.com/user-attachments/assets/ea4c0fe1-361d-4f00-b215-870f4e1be2bb)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.