首页 > 解决方案 > Visual Studio Community 2019 creates a project but cannot open the project it created?

问题描述

I have Visual Studio Community 2019 v16.3.7.

According to dotnet --list-sdks I have the following SDKs installed

2.1.802 [C:\Program Files\dotnet\sdk]
2.2.301 [C:\Program Files\dotnet\sdk]
3.0.100 [C:\Program Files\dotnet\sdk]
3.0.100 [C:\Users\bugma\scoop\apps\dotnet-sdk\current\sdk]

I just created a .NET Core DLL project. It created the following sln and csproj files:

Solution:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29424.173
MinimumVisualStudioVersion = 10.0.40219.1
Global
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
    GlobalSection(ExtensibilityGlobals) = postSolution
        SolutionGuid = {26BC7AEA-9E58-472D-8800-8D620A97AED6}
    EndGlobalSection
EndGlobal

CSProj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
  </PropertyGroup>

</Project>

a Class1.cs file is also in the folder.

If I shutdown Visual Studio and launch Visual Studio from the .sln file, the Solution Explorer tells me that 0 projects have been loaded.

If I shutdown Visual Studio again and launch from the .csproj file, I get a dialog box that says, "One or more errors occurred." I click on the "OK" button and select "View > Output" and "View > Error List" but both panels are empty. So where do I find information about the error?

This is all a bit weird and frustrating. You'd expect that a project that Visual Studio creates is then able to be opened in Visual Studio and worked on.

LATER

I have stripped out the scoop-installed dotnet SDK. Now dotnet --list-sdks says

1.0.0-preview2-003131 [C:\Program Files\dotnet\sdk]
3.0.100 [C:\Program Files\dotnet\sdk]

This has not improved anything though.

标签: c#.net-corevisual-studio-2019

解决方案


我认为您错过了 Project 文件中的 OutputType,因此它无法正常工作。请添加属性 <OutputType>Exe</OutputType>。让我知道它是否对您有用

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
    <OutputType>Exe</OutputType>
  <TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

</Project>

推荐阅读