Search code examples
c#asp.net-mvcvisual-studiomsbuildvisual-studio-2019

Project gets unloaded when opening with Visual Studio 2019


I am trying to open a solution using Visual studio 2019 and visual studio 2017. All the projects in the solution are loading except for one. When trying to load the unloaded project i get an error in the output window as

TakstMVC.csproj : error : The imported project "....build\MSBuild.Community.Tasks.targets" was not found. Confirm that the expression in the Import declaration "TakstMVC\.....build\MSBuild.Community.Tasks.targets" is correct, and that the file exists on disk. TakstMVC\FluentMigrator.targets

When i tried to open using VS 2017 i saw a migration report which said

TakstMVC.csproj: The application which this project type is based on was not found. Please try this link for further information: http://go.microsoft.com/fwlink/?LinkID=299083&projecttype=E3E379DF-F4C6-4180-9B81-6769533ABE47

Part of the .csproj of the project is as below:

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>
    </ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{A4354F5C-ECF5-4621-AA9E-B91FE543F096}</ProjectGuid>
    <ProjectTypeGuids>{E3E379DF-F4C6-4180-9B81-6769533ABE47};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>TakstMVC</RootNamespace>
    <AssemblyName>TakstMVC</AssemblyName>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <MvcBuildViews>false</MvcBuildViews>
    <UseIISExpress>true</UseIISExpress>
    <SccProjectName>SAK</SccProjectName>
    <SccLocalPath>SAK</SccLocalPath>
    <SccAuxPath>SAK</SccAuxPath>
    <SccProvider>SAK</SccProvider>
    <FileUpgradeFlags>
    </FileUpgradeFlags>
    <UpgradeBackupLocation>
    </UpgradeBackupLocation>
    <OldToolsVersion>4.0</OldToolsVersion>
    <IISExpressSSLPort />
    <IISExpressAnonymousAuthentication />
    <IISExpressWindowsAuthentication />
    <IISExpressUseClassicPipelineMode />
    <MvcProjectUpgradeChecked>true</MvcProjectUpgradeChecked>
    <NuGetPackageImportStamp>
    </NuGetPackageImportStamp>
  </PropertyGroup>

I have the following installed in my computer

  • Microsoft .NET Framework 4.7.1 SDK
  • Microsoft .NET Framework 4.7.1 SDK Targeting Pack (ENU)
  • Microsoft .NET Core 3.1.1 - Windowsserver hosting
  • Microsoft .NET Core SDK 3.1.101 (x64)
  • Microsoft .NET Core SDK 2.2.207 (x64)
  • Microsoft .NET Core Runtime - 3.1.1
  • Microsoft .NET Core Runtime - 2.2.8

I tried to install dotnetfx35.exe but it doesnt even run when executed (not even a message or error). The windows feature are as below: enter image description here

How can I identify the target framework of the project and load it in visual studio successfully ? appreciate some advise on this.


Solution

  • The error is clear that you did not import the MSBuild.Community.Tasks.targets correctly on your local area. The reason is that you did not install MSBuild.Community.Tasks.targets on your PC or the import path from csproj file is incorrect.

    You should check this document to install the right target.

    First, remove xml node under csproj file like these:

     <Import Project="..\build\MSBuild.Community.Tasks.targets" Condition="Exists('..\build\MSBuild.Community.Tasks.targets')" />
    
    
     <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
        <PropertyGroup>
          <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
        </PropertyGroup>
        <Error Condition="!Exists('..\build\MSBuild.Community.Tasks.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\build\MSBuild.Community.Tasks.targets'))" />
      </Target>
    

    Second, install the msi file.

    then, add these under the csproj file:

    <Import Project="C:\Program Files (x86)\MSBuild\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
    

    Besides, you could also use nuget function. First, uninstall the nuget package if you have a old version on the project. Then, use the first suggestion to remove any previous import projects="xxx\MSBuildTasks.targets". After that, install the MSBuildTasks nuget package. That is the same.

    Update

    Try to You should change ..\..\ to ..\. Use the right path.

    Or use this command under Tools-->Nuget Package Manager-->Package Manager Console

    update-package -reinstall
    

    Answer from the Customer

    embarrassingly enough the whole issue was with the solution path where my solution was located in my local computer. I had a long path including a folder having two words as well. After trying everything else I moved the solution folder to C:\temp folder and the issue was no longer there. The error showed in VS was quite misleading. What a waist of time. Thank you for your efforts !