Add support for `dotnet publish --no-build`
- Dominant language
- C#
- Stars
- 2.9k
- Forks
- 576
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 123
Description
*Migrated from: https://github.com/dotnet/sdk/issues/35705*
---
Using a very specific combination of dotnet CLI arguments and msbuild properties, .NET 7 (and lower?) would allow you to run a publish with `--no-build`. This no longer works when I upgrade my solution to use .NET 8, but only specifically breaks for Xamarin projects (i.e. has `net8.0-macos` target framework).
### Steps to Reproduce
1. Clone the following repo and checkout the `dotnet8/dotnet8` branch: https://github.com/jwosty/DotnetMacosNoBuildBug/tree/dotnet8/dotnet8
2. Run `build.sh`.
3. Observe the following failure:
```
/usr/local/share/dotnet/packs/Microsoft.macOS.Sdk/13.3.8825-net8-rc1/targets/Xamarin.Shared.Sdk.targets(303,3): error : Both RuntimeIdentifier and RuntimeIdentifiers were passed on the command line, but only one of them can be set at a time. [/Users/jwostenberg/Code/DotnetMacosNoBuildBug/src/TestApp/TestApp.csproj]
```
It works if you change everything to use .NET 7 (or checkout the `dotnet7/dotnet7` branch).
So while this technically a breaking change, this makes sense. However, I cannot find another workaround. There's another branch, `dotnet8/rids-in-proj`, where I've attempted a workaround by setting `RuntimeIdentifiers` in the project file instead. I get the following warning:
```
/usr/local/share/dotnet/packs/Microsoft.macOS.Sdk/13.3.8825-net8-rc1/targets/Xamarin.Shared.Sdk.targets(299,3): warning : RuntimeIdentifier was set on the command line, and will override the value for RuntimeIdentifiers set in the project file. [/Users/jwostenberg/Code/DotnetMacosNoBuildBug/src/TestApp/TestApp.csproj]
```
which is fine and I can live with, but also the following failure:
```
/usr/local/share/dotnet/sdk/8.0.100-rc.1.23463.5/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(235,5): error NETSDK1085: The 'NoBuild' property was set to true but the 'Build' target was invoked. [/Users/jwostenberg/Code/DotnetMacosNoBuildBug/src/TestLibrary/TestLibrary.csproj]
```
Interestingly, this behavior happens on .NET 7 too (I must have been setting it via the CLI already to work around that). The same behavior happens even if you don't even set `RuntimeIdentifiers` at all for build and publish, specifically.
Additionally, the publish succeeds if you change the FrameworkTarget from `net8.0-macos` to `net8.0` (however it doesn't produce an app executable).
### Environment
CLI, no IDE.
Version information
``dotnet --info`` output:
```
.NET SDK:
Version: 8.0.100-rc.1.23463.5
Commit: e7f4de8816
Runtime Environment:
OS Name: Mac OS X
OS Version: 13.5
OS Platform: Darwin
RID: osx-arm64
Base Path: /usr/local/share/dotnet/sdk/8.0.100-rc.1.23463.5/
.NET workloads installed:
[macos]
Installation Source: SDK 8.0.100-rc.1
Manifest Version: 13.3.8825-net8-rc1/8.0.100-rc.1
Manifest Path: /usr/local/share/dotnet/sdk-manifests/8.0.100-rc.1/microsoft.net.sdk.macos/WorkloadManifest.json
Install Type: FileBased
Host:
Version: 8.0.0-rc.1.23419.4
Architecture: arm64
Commit: 92959931a3
RID: osx-arm64
.NET SDKs installed:
6.0.302 [/usr/local/share/dotnet/sdk]
6.0.403 [/usr/local/share/dotnet/sdk]
6.0.404 [/usr/local/share/dotnet/sdk]
6.0.405 [/usr/local/share/dotnet/sdk]
6.0.407 [/usr/local/share/dotnet/sdk]
7.0.100 [/usr/local/share/dotnet/sdk]
7.0.101 [/usr/local/share/dotnet/sdk]
7.0.102 [/usr/local/share/dotnet/sdk]
7.0.200 [/usr/local/share/dotnet/sdk]
7.0.202 [/usr/local/share/dotnet/sdk]
7.0.400 [/usr/local/share/dotnet/sdk]
8.0.100-preview.7.23376.3 [/usr/local/share/dotnet/sdk]
8.0.100-rc.1.23463.5 [/usr/local/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.7 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.12 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.13 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.15 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.10 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0-preview.7.23375.9 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0-rc.1.23421.29 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.11 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.12 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.15 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.10 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0-preview.7.23375.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0-rc.1.23419.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
x64 [/usr/local/share/dotnet/x64]
registered at [/etc/dotnet/install_location_x64]
Environment variables:
Not set
global.json file:
/Users/jwostenberg/Code/Bug8/global.json
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
```
### Build Logs
.NET 8 - `dotnet publish` binlog:
[publish8.binlog.zip](https://github.com/xamarin/xamarin-macios/files/12827486/publish8.binlog.zip)
.NET 7 - `dotnet publish` binlog for comparison:
[publish7.binlog.zip](https://github.com/xamarin/xamarin-macios/files/12827492/publish7.binlog.zip)
### Example Project (If Possible)
https://github.com/jwosty/DotnetMacosNoBuildBug/tree/dotnet8/dotnet8
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.