dotnet / dotnet/project-system

Publish can cause a restore of the non-active configuration, leading to broken IDE behaviour

Open
#8,338 3 comments 0 reactions 0 assignees View on GitHub
Triage-Approved
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:

![image](https://user-images.githubusercontent.com/350947/180127082-a0253020-d4e6-40eb-8a1d-5971e29eae3b.png)

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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.