如何将 .NET Framework Visual Studio 项目升级为 SDK 样式?

问题描述 投票:0回答:1

使用 Microsoft Upgrade Assistant 而不更改我的 ASP.NET MVC 项目 .NET Framework 目标 (4.7.2) 后,出现以下错误。我怎样才能摆脱它?

错误 NETSDK1022 包含重复的“内容”项目。 .NET SDK 默认情况下包含项目目录中的“内容”项。你 可以从项目文件中删除这些项目,或者设置 如果需要,可将“EnableDefaultContentItems”属性设置为“false” 明确地将它们包含在您的项目文件中。了解更多信息, 请参阅https://aka.ms/sdkimplicititems。重复的项目是: '视图\Web.config'; 'Web.config'; 'Web.调试.config'; 'Web.Release.config';...

这是生成的 Visual Studio 项目的初始部分。该问题与

OutputType
字段有关。所有可能的选项都不允许我像非 SDK VStudio 项目文件样式那样调试或运行项目:

<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
  <TargetFramework>net472</TargetFramework>
  <OutputType>Exe</OutputType>
  <TypeScriptToolsVersion>4.3</TypeScriptToolsVersion>
  <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  <EnableDefaultItems>false</EnableDefaultItems>
  <PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
  <OutputPath>bin\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
  <Optimize>false</Optimize>
  <OutputPath>bin\</OutputPath>
</PropertyGroup>
<ItemGroup>
  <Reference Include="System.Data.OracleClient" />
  <Reference Include="System.Net" />
  <Reference Include="System.Security" />
  <Reference Include="System.ServiceModel" />
  <Reference Include="System.ServiceProcess" />
  <Reference Include="System.Transactions" />
  <Reference Include="System.Configuration" />
</ItemGroup>
<ItemGroup>
<Compile Update="Models\ConnectionHistory.cs">
  <DependentUpon>devDeptModel.tt</DependentUpon>
</Compile>

...
c# asp.net-mvc visual-studio upgrade
1个回答
0
投票

类型为图书馆。

我从GIthub找到了一个示例sdk风格的项目: https://github.com/xin9le/SdkStyle_AspNet/tree/main

要测试该项目,

  1. 我修改了csproj文件:

    错误的 C:\Program Files\Microsoft Visual Studio�2\Community\MSBuild\Microsoft\VisualStudio $(VisualStudioVersion) 图书馆

以及封装版本:

 <PackageReference Include="Microsoft.AspNet.Mvc" Version="5.2.9" />
  1. webconfig
    文件中

.net框架版本:

<system.web>
    <compilation debug="true" targetFramework="4.7.2" />
    <httpRuntime targetFramework="4.7.2" />
</system.web>

套装版本:

   <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.2.9.0" newVersion="5.2.9.0" />
    </dependentAssembly>

3.并修改Launchsetting.json文件。 我从asp.net core mvc模板复制它并选择开始

IIS Express

{
    "$schema": "http://json.schemastore.org/launchsettings.json",
    "iisSettings": {
        "windowsAuthentication": false,
        "anonymousAuthentication": true,
        "iisExpress": {
            "applicationUrl": "http://localhost:5522",
            "sslPort": 44344
        }
    },
    "profiles": {
        "http": {
            "commandName": "Project",
            "dotnetRunMessages": true,
            "launchBrowser": true,
            "applicationUrl": "http://localhost:5019",
            "environmentVariables": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            }
        },
        "https": {
            "commandName": "Project",
            "dotnetRunMessages": true,
            "launchBrowser": true,
            "applicationUrl": "https://localhost:7118;http://localhost:5019",
            "environmentVariables": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            }
        },
        "IIS Express": {
            "commandName": "IISExpress",
            "launchBrowser": true,
            "environmentVariables": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            }
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.