Warm tip: This article is reproduced from serverfault.com, please click

其他-新的csproj文件结构可以与ASP.NET Framework项目一起使用吗?

(其他 - Can the new csproj file structure be used with a ASP.NET Framework project?)

发布于 2017-12-20 22:36:47

新的.csproj格式对经典文件进行了一些重大改进,包括与NuGet软件包管理的紧密集成以及冗长的结构。我想在仍然使用.NET Framework 4.6和ASP.NET的同时获得这些好处(因为我的项目依赖于尚未产生.NET Core版本的Umbraco)。

最大的挑战似乎是调试经验-ASP.NET Core项目希望运行dotnet核心应用程序并为IIS实例设置反向代理。该过程完全与.NET Framework模型无关,我不知道从哪里开始尝试在Visual Studio中设置调试。

有什么办法可以将这两个项目模型混合使用?

Questioner
Paul Turner
Viewed
0
CodeFuller 2018-04-05 00:14:55

GitHub上有很多关于ASP.NET(非核心)应用程序支持新的csproj格式的开放性问题。他们中的一些:

你可能已经了解,ASP.NET应用程序尚不支持新的csproj格式。可以使其工作,但是它并不流畅。

前一段时间,我想以新的csproj格式创建ASP.NET MVC项目,只是为了好玩。我使它工作了,但是我并没有玩太多。因此,了解你的经历将很有趣。

步骤如下:

  1. 删除旧的不需要的项目文件:

    • MvcApplication.csproj
    • MvcApplication.csproj.user
    • packages.config
  2. 使用以下内容创建新的MvcApplication.csproj:

    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
        <TargetFramework>net461</TargetFramework>
      </PropertyGroup>
    
      <PropertyGroup>
        <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
        <OutputPath>bin\</OutputPath>
      </PropertyGroup>
    
      <ItemGroup>
        <PackageReference Include="Antlr" version="3.4.1.9004" />
        <PackageReference Include="bootstrap" version="3.0.0" />
        <PackageReference Include="jQuery" version="1.10.2" />
        <PackageReference Include="jQuery.Validation" version="1.11.1" />
        <PackageReference Include="Microsoft.ApplicationInsights" version="2.2.0" />
        <PackageReference Include="Microsoft.ApplicationInsights.Agent.Intercept" version="2.0.6" />
        <PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" version="2.2.0" />
        <PackageReference Include="Microsoft.ApplicationInsights.PerfCounterCollector" version="2.2.0" />
        <PackageReference Include="Microsoft.ApplicationInsights.Web" version="2.2.0" />
        <PackageReference Include="Microsoft.ApplicationInsights.WindowsServer" version="2.2.0" />
        <PackageReference Include="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" version="2.2.0" />
        <PackageReference Include="Microsoft.AspNet.Mvc" version="5.2.3" />
        <PackageReference Include="Microsoft.AspNet.Razor" version="3.2.3" />
        <PackageReference Include="Microsoft.AspNet.Web.Optimization" version="1.1.3" />
        <PackageReference Include="Microsoft.AspNet.WebPages" version="3.2.3" />
        <PackageReference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.5" />
        <PackageReference Include="Microsoft.CSharp" Version="4.4.1" />
        <PackageReference Include="Microsoft.jQuery.Unobtrusive.Validation" version="3.2.3" />
        <PackageReference Include="Microsoft.Net.Compilers" version="2.1.0" developmentDependency="true" />
        <PackageReference Include="Microsoft.Web.Infrastructure" version="1.0.0.0" />
        <PackageReference Include="Modernizr" version="2.6.2" />
        <PackageReference Include="Newtonsoft.Json" version="6.0.4" />
        <PackageReference Include="Respond" version="1.2.0" />
        <PackageReference Include="WebGrease" version="1.5.2" />
      </ItemGroup>
    
      <ItemGroup>
        <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
      </ItemGroup>
    
      <ItemGroup>
        <Reference Include="System.Web" />
      </ItemGroup>
    
      <ItemGroup>
        <Compile Update="Global.asax.cs">
          <DependentUpon>Global.asax</DependentUpon>
        </Compile>
      </ItemGroup>
    
      <ItemGroup>
        <Content Include="Web.config">
          <SubType>Designer</SubType>
        </Content>
        <Content Include="Web.*.config">
          <DependentUpon>Web.config</DependentUpon>
          <SubType>Designer</SubType>
        </Content>
      </ItemGroup>
    
    </Project>
    

    上面的长软件包列表包括为默认ASP.NET MVC应用程序添加的默认软件包。你应该添加应用程序使用的其他软件包。

    不要忘了添加Microsoft.CSharp软件包,否则你将在ViewBag分配时收到以下编译错误

    错误CS0656:缺少编译器所需的成员'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'

    在ASP.NET项目中,Microsoft.CSharp添加为对该项目的引用。但是最好将其作为NuGet包使用。

    唯一无法避免的直接参考是System.Web

  3. 调试项目

    当你说调试可能会很痛苦时,你是对的。由于Visual Studio不知道它是ASP.NET应用程序,因此没有立即启动调试会话的方法。

    我在这里看到2种可能的解决方案:

    一种。使用IIS Express进行调试。

    基于IIS Express可执行文件配置调试非常容易。只需创建以下调试配置文件:

    在此处输入图片说明

    对应的launchSettings.json:

    {
      "profiles": {
        "ASP.NET Old csproj": {
          "commandName": "Executable",
          "executablePath": "c:\\Program Files\\IIS Express\\iisexpress.exe",
          "commandLineArgs": "/path:\"$(SolutionDir)$(ProjectName)\" /port:12345"
        }
    }
    

    b。使用IIS进行调试。

    在IIS管理器中,创建指向你的项目目录的应用程序。现在,你可以通过附加到w3wp.exe进程来调试应用程序。

这是GitHub上的示例项目按照上面的步骤,它基本上是默认的ASP.NET MVC项目,已迁移为新的csproj格式。可以对其进行编译,执行和调试(包括IIS Express的配置文件)