project-system icon indicating copy to clipboard operation
project-system copied to clipboard

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

Open drewnoakes opened this issue 3 years ago • 3 comments

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:
    <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>
    
  2. Add code that uses that dependency in one configuration only. For example:
    #if DEBUG
            _ = Figgle.FiggleFonts.Acrobatic;
    #endif
    
  3. 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>
    
  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

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.

drewnoakes avatar Jul 21 '22 03:07 drewnoakes

I would verify that this is actually us restoring, or whether its the command-line restore running in-proc/.

davkean avatar Jul 21 '22 04:07 davkean

@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:

  1. Suppress receipt of project data somehow
  2. Allow the restore / build / publish operations to occur
  3. Re-restore the project with the original configuration
  4. Unblock project data handling

drewnoakes avatar Jul 21 '22 21:07 drewnoakes

If its the command-line there's nothing the project can do to suppress it.

davkean avatar Jul 21 '22 22:07 davkean