dotnet / dotnet/sdk

Inconsistent dotnet build behaviour between configurations

Open
#45,200 0 comments 0 reactions 1 assignee Claimed by @joeloff 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
Building application with project reference on another project seems to behave differently depending on which configuration you're building and whether you're building project alone or a solution file containing the project.
Unsure if this is a bug, or if I'm misunderstanding how solution files work and this is intended.

### To Reproduce
Clone repo: https://github.com/woodylaurence/DotNetBuildIssueRepro.git

Create solution file and add the Application project to it:
`dotnet new sln --name "solution_file"`
`dotnet sln solution_file.sln add Application/Application.csproj`

Then build solution file in Release configuration and try and publish Application in same configuration:
`dotnet build solution_file.sln --configuration Release`
`dotnet publish Application/Application.csproj --configuration Release --no-build`

Get the following error:

> /usr/lib/dotnet/sdk/8.0.110/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Publish.targets(351,5): error MSB3030: Could not copy the file "/home/laurence/RiderProjects/DotNetBuildIssueRepro/LibraryProject/bin/Release/net8.0/LibraryProject.dll" because it was not found. [/home/laurence/RiderProjects/DotNetBuildIssueRepro/Application/Application.csproj]

bin/Release/net8.0 folder is empty after this step, hence the error.

If you instead build and publish Application in Debug configuration everything works:
`dotnet build solution_file.sln --configuration Debug`
`dotnet publish Application/Application.csproj --configuration Debug --no-build`

If you clean up and then only build the project, rather than the solution, everything works:
`dotnet clean Application/Application.csproj --configuration Release && dotnet clean LibraryProject/LibraryProject.csproj --configuration Release`
`dotnet build Application/Application.csproj --configuration Release`
`dotnet publish Application/Application.csproj --configuration Release --no-build`

### Exceptions (if any)
See above error message.

### Further technical details
`dotnet --info` output:
.NET SDK:
Version: 8.0.110
Commit: 87a66bb3d1
Workload version: 8.0.100-manifests.9143487c

Runtime Environment:
OS Name: ubuntu
OS Version: 24.04
OS Platform: Linux
RID: ubuntu.24.04-x64
Base Path: /usr/lib/dotnet/sdk/8.0.110/

.NET workloads installed:
Workload version: 8.0.100-manifests.9143487c
There are no installed workloads to display.

Host:
Version: 8.0.10
Architecture: x64
Commit: 81cabf2857

.NET SDKs installed:
8.0.110 [/usr/lib/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.10 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.10 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
None

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

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.