dotnet / project-system

The .NET Project System for Visual Studio
MIT License
967 stars 385 forks source link

Unload/reload a project in VisualStudio may leave something broken #5977

Open quetzalcoatl opened 4 years ago

quetzalcoatl commented 4 years ago

Visual Studio Version: Microsoft Visual Studio Community 2019 Version 16.4.3

Summary: Similar to https://github.com/dotnet/project-system/issues/3773
After upgrading a few project to new-style csproj file, some projects (not necessarily those upgraded!) became 'Skipped' while Clean/Build/Rebuild operations in VisualStudio. Especially similar to report from Nekromancer - I of course checked the checkbox list in Configuration Manager and all projects were selected to be built.

Steps to Reproduce: I cannot guarantee a successful repro, because it's already fixed on my machine. I can only summarize the that I did during "upgrading" projects. The "porting" was done manually by on project-by-project basis: 0) do not close Solution, do not close VisualStudio, keep Solution open 1) unload specific old-style project 2) manually edit csproj file so it's now in new-style 3) remove packages.json, add packagereferences to csproj 4) load the project back 5) trim AssemblyInfo 6) try to build the project or whole solution

Expected Behavior: After re-loading all projects, all projects in Solution are Cleaned/Built/Rebuilt when I try cleaning/building/rebuilding the Solution respectively.

Actual Behavior: Some (most) projects were skipped without any log message. Typical build output was: ==== Build: 0 succeeded, 0 failed, 0 up-to-date, 5 skipped ==== Once in every few attempts I got most-recently-upgraded project start responsing and get cleaned/built, but none of its dependencies or other unrelated projects in the same solution.

User Impact: Irritation. No further impact, as I found a simple workaround. https://github.com/dotnet/project-system/issues/3773 suggested removing and adding the project to the solution, it was not necessary. Closing the solution and reopening it was enough - after reopening the solution everything was back to normal.

TekuSP commented 4 years ago

Same problem, after upgrading projects and reloading them in Visual Studio, Visual Studio skips them. msbuild solution.sln works totally fine. Reloading did not help, curiously some converted projects do work, others don't. Its over 400 projects, so no luck with removing/readding.

Please, any idea how to fix?

quetzalcoatl commented 4 years ago

@TekuSP did you check ConfigurationManager? Right click on Solution in Solution Explorer, pick Properties, inspect all options - there should be a table with checkboxes that allow you to turn on/off building a project in given Configuration/Platform. Be sure to inspect all Configurations/Platforms, as your project(s) could be skipped either in a mode-specific cfg, or in the global fallback cfg as well.

If it's not this, then close solution & reopen, or close VS & reopen.. I've not seen/heard about any other workarounds for this.

TekuSP commented 4 years ago

Everything is checked to build. For example Rider from JetBrains builds it without problems and finds correct configuration. Restarted visual studio. Reloaded project.

Not helped.

davkean commented 4 years ago

Sending back to Triage so that someone gets assigned.

drewnoakes commented 4 years ago

Triage notes: Try to reproduce this.

TekuSP commented 3 years ago

If <PlatformTarget>x64</PlatformTarget> is in first PropertyGroup in CSPROJ, build is skipped, when no other PlatformTarget is found. For example:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>8.0.30703</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{84910DD5-B5BE-4FE2-89D3-877EEDA657B1}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>CI.DataStorage</RootNamespace>
    <AssemblyName>CI.DataStorage</AssemblyName>
    <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <TargetFrameworkProfile />
    <PlatformTarget>x64</PlatformTarget>
    <AppendTargetFrameworkToOutputPath>False</AppendTargetFrameworkToOutputPath>
  </PropertyGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

And that is automatically skipped, with no error whatsoever. But if you have this:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>8.0.30703</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{84910DD5-B5BE-4FE2-89D3-877EEDA657B1}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>CI.DataStorage</RootNamespace>
    <AssemblyName>CI.DataStorage</AssemblyName>
    <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <TargetFrameworkProfile />
    <AppendTargetFrameworkToOutputPath>False</AppendTargetFrameworkToOutputPath>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>..\..\bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <DebugType>full</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <LangVersion>7.3</LangVersion>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
    <OutputPath>..\..\bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <Optimize>true</Optimize>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <LangVersion>7.3</LangVersion>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

This compiles fine. It would be great if you could at least tell us Developers WHAT IS WRONG with CSPROJ.