新的csproj文件结构可以与ASP.NET Framework项目一起使用吗? [英] Can the new csproj file structure be used with a ASP.NET Framework project?

查看:78
本文介绍了新的csproj文件结构可以与ASP.NET Framework项目一起使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

The new .csproj format includes some significant improvements over the classic files, including tight integration with NuGet package management and significantly less-verbose structure. I want to gain these benefits whilst still using the .NET Framework 4.6 and ASP.NET (because my project depends on Umbraco which has yet to produce a .NET Core version).

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

The biggest challenge would seem to be the debugging experience - an ASP.NET Core project expects to run a dotnet core application and set up a reverse proxy to an IIS instance. This process is completely alien to the .NET Framework model and I wouldn't know where to start trying to set up debugging in Visual Studio.

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

Is there any way to get these two project models to mix?

推荐答案

在GitHub上有很多关于对ASP.NET(非核心)应用程序支持新的csproj格式的公开问题.其中一些:

There is a bunch of open issues on GitHub regarding support of new csproj format for ASP.NET (non-Core) applications. Some of them:

  • Using the new .Csproj without .Net core #1688
  • Add support for ASP.NET (non-Core) projects #2670
  • Support for "classic" ASP.NET #1978

您可能已经了解,ASP.NET应用程序尚不支持新的csproj格式.可以使其正常运行,但是并不顺利.

As you probably already understood, new csproj format is not yet supported for ASP.NET applications. It's possible to make it work, however it won't be smooth.

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

Some time ago I have tried to create ASP.NET MVC project in new csproj format, just for fun. I made it work, however I had not played with it a lot. So it will be interesting to know your experience.

步骤如下:

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

  1. Remove old unrequired project files:

  • MvcApplication.csproj
  • MvcApplication.csproj.user
  • packages.config

使用以下内容创建新的MvcApplication.csproj:

Create new MvcApplication.csproj with the following content:

<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应用程序添加的默认软件包.您应该添加应用程序使用的其他软件包.

The long package list above includes default packages added for default ASP.NET MVC application. You should add other packages used by your application.

别忘了添加Microsoft.CSharp包,否则在ViewBag分配上会出现以下编译错误:

Don't forget to add the Microsoft.CSharp package, otherwise you'll get following compilation error on ViewBag assignments:

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

error CS0656: Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'

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

In ASP.NET projects, Microsoft.CSharp is added as reference to the project. But it's better to consume it as NuGet package.

唯一不能避免的直接引用是System.Web.

The only direct reference that could not be avoided is a System.Web.

调试项目

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

You were right when said that debugging could be a pain. Since Visual Studio does not know it's an ASP.NET application, there is no instant method to start debugging session.

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

I see 2 possible solutions here:

a.使用IIS Express进行调试.

a. Use IIS Express for debugging.

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

It's quite easy to configure debugging based on IIS Express executable. Just create the following debugging profile:

对应的launchSettings.json:

Corresponding 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进行调试.

b. Use IIS for debugging.

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

In IIS Manager create application that points to directory with your project. Now you could debug your application by attaching to w3wp.exe process.

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

Here is Sample Project on GitHub. It is basically default ASP.NET MVC project migrated to new csproj format following above steps. It could be compiled, executed and debugged (profile for IIS Express included)

这篇关于新的csproj文件结构可以与ASP.NET Framework项目一起使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆