dotnet / dotnet/project-system
Publish can cause a restore of the non-active configuration, leading to broken IDE behaviour
- Dominant language
- C#
- Stars
- 1k
- Forks
- 415
- PR merge metrics
- No merged PRs in 30d
Description
## Visual Studio Version
Version 17.4.0 Preview 1.0 [32718.10.main]
I suspect this has existed for a while.
## Summary
Found while testing #8336.
## Steps to Reproduce
1. Create a project with a reference that exists only in `DEBUG` configuration. For example:
```xml
Exe
net6.0
```
2. Add code that uses that dependency in one configuration only. For example:
```c#
#if DEBUG
_ = Figgle.FiggleFonts.Acrobatic;
#endif
```
3. Configure a publish profile that always publishes in RELEASE mode. For example:
```xml
Release
Any CPU
bin\Release\net6.0\publish\
FileSystem
<_TargetId>Folder
net6.0
false
```
4. Ensure VS's active configuration is DEBUG and that the IDE shows no errors
5. Enable _Show All Files_ in Solution Explorer and open the `project.assets.json` file to see that the package's details are present.
6. Publish the project
## Expected Behavior
Publish completes successfully and user continues from where they left off.
## Actual Behavior
Publish completes successfully, but IDE now shows a compile error:

Building also produces the error, as the reference is not provided to the compiler.
Attempting to restore the solution's packages doesn't help either.
## Analysis
The publish triggers a build in RELEASE mode, which performs a restore. This causes the assets file to be updated, removing any mention of the NuGet package. The IDE picks up that change and tells Roslyn that the reference no longer exists.
I'm not clear on how to fix this bug, or which team should own it.
Contributor guide
Assessment
This issue has not been assessed yet.