Open
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 <ArtifactsPath>...</ArtifactsPath>
in Directory.Build.props
, but same result.
To Reproduce
- Create an empty solution
- Add a .NET 8 GUI app project to it (into a subdirectory, i.e.
src/<project-name>/
) - Add a Directory.Build.props to the root solution directory with the following contents:
<Project>
<PropertyGroup>
<NoWarn>1701;1702;2087;2091</NoWarn>
<CodeAnalysisTreatWarningsAsErrors>false</CodeAnalysisTreatWarningsAsErrors>
<SatelliteResourceLanguages>en-US</SatelliteResourceLanguages>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<BaseIntermediateOutputPath>$(SolutionDir)build\intermediate\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
<OutDir>$(SolutionDir)build\staging\bin\$(MSBuildProjectName)\$(Configuration)-$(Platform)\</OutDir>
</PropertyGroup>
</Project>
- Add this to the .csproj of the created project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!--- ... -->
<OutputType>WinExe</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PublishAot>false</PublishAot>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>true</PublishTrimmed>
<PublishReadyToRun>true</PublishReadyToRun>
<IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
<EnableDefaultContentItems>false</EnableDefaultContentItems>
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
<RegisterForCOMInterop>false</RegisterForCOMInterop>
<NoVBRuntimeReference>true</NoVBRuntimeReference>
<EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>
</PropertyGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="echo ProjectDir: $(ProjectDir)" />
<Exec Command="echo BaseIntermediateOutputPath: $(BaseIntermediateOutputPath)" />
<Exec Command="dotnet restore $(ProjectDir)$(MSBuildProjectName).csproj -r $(RuntimeIdentifier) --disable-build-servers" />
<Exec Command="dotnet publish $(ProjectDir)$(MSBuildProjectName).csproj -r $(RuntimeIdentifier) -c $(Configuration) --disable-build-servers --no-restore -o $(SolutionDir)build\out\$(MSBuildProjectName)\$(Configuration)-$(Platform)\win\" />
</Target>
</Project>
- Run project build via Visual Studio
- 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 "") - The
dotnet publish
command will later fail withRoot assembly 'build\intermediate\<project-name>\<configuration>\<project-name>.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: <project-name>, Configuration: <configuration> x64 ------
1><project-name> -> <solution root>\build\staging\bin\<project-name>\<configuration>-x64\<project-name>.dll
1>ProjectDir: <solution root>\src\<project-name>\
1>BaseIntermediateOutputPath: <solution root>\build\intermediate\<project-name>\
1> Determining projects to restore...
1> Restored <solution root>\src\<project-name>\<project-name>.csproj (in 199 ms).
1> Optimizing assemblies for size. This process might take a while.
1>ILLink : error IL1032: Root assembly 'build\intermediate\<project-name>\<configuration>\<project-name>.dll' could not be found. [<solution root>\src\<project-name>\<project-name>.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. [<solution root>\src\<project-name>\<project-name>.csproj]
1>
1>Workload updates are available. Run `dotnet workload list` for more information.
1><solution root>\src\Runtime\HostApp\Loader\<project-name>\<project-name>.csproj(37,3): error MSB3073: The command "dotnet publish <solution root>\src\<project-name>\<project-name>.csproj -r win-x64 -c Internal_LocalDev --disable-build-servers --no-build -o <solution root>\build\out\<project-name>\<configuration>-x64\win\" exited with code 1.
1>Done building project "<project-name>.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 inBaseIntermediateOutputPath
: