project-system
project-system copied to clipboard
Publish can cause a restore of the non-active configuration, leading to broken IDE behaviour
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
- Create a project with a reference that exists only in
DEBUGconfiguration. For example:<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net6.0</TargetFramework> </PropertyGroup> <ItemGroup Condition=" '$(Configuration)' == 'DEBUG' "> <PackageReference Include="Figgle" Version="0.4.0" /> </ItemGroup> </Project> - Add code that uses that dependency in one configuration only. For example:
#if DEBUG _ = Figgle.FiggleFonts.Acrobatic; #endif - Configure a publish profile that always publishes in RELEASE mode. For example:
<Project> <PropertyGroup> <Configuration>Release</Configuration> <Platform>Any CPU</Platform> <PublishDir>bin\Release\net6.0\publish\</PublishDir> <PublishProtocol>FileSystem</PublishProtocol> <_TargetId>Folder</_TargetId> <TargetFramework>net6.0</TargetFramework> <SelfContained>false</SelfContained> </PropertyGroup> </Project> - Ensure VS's active configuration is DEBUG and that the IDE shows no errors
- Enable Show All Files in Solution Explorer and open the
project.assets.jsonfile to see that the package's details are present. - 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.
I would verify that this is actually us restoring, or whether its the command-line restore running in-proc/.
@davkean can you elaborate on what difference that would make? Is that just for triaging purposes, or something else?
The project needs to be restored for the publish build to complete, and as there's one project.assets.json file for all configurations, I don't see how the above issue can easily be solved.
The only idea I see is to:
- Suppress receipt of project data somehow
- Allow the restore / build / publish operations to occur
- Re-restore the project with the original configuration
- Unblock project data handling
If its the command-line there's nothing the project can do to suppress it.