新的.csproj格式对classic 文件进行了一些重大改进,包括与NuGet软件包管理的紧密集成,以及显著减少了冗长的 struct .我希望在继续使用的同时获得这些好处.NET框架4.6和ASP.NET(因为我的项目依赖于Umbraco,它还没有生成.NET核心版本).

最大的挑战似乎是调试体验——ASP.NET Core项目希望运行一个dotnet Core应用程序,并为IIS实例设置一个反向代理.这一过程与美国完全不同.NET框架模型,我不知道从哪里开始try 在Visual Studio中设置调试.

有没有办法把这两个项目模型混合起来?

推荐答案

关于支持ASP的新csproj格式,GitHub上有很多悬而未决的问题.NET(非核心)应用程序.其中一些:

正如您可能已经理解的,ASP还不支持新的csproj格式.NET应用程序.这是有可能的,但它不会顺利.

不久前,我try 创建ASP.NET MVC项目,新的csproj格式,只是为了好玩.我成功了,但是我没有经常玩它.所以了解你的经历会很有趣.

步骤如下:

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

    • MVC应用程序.项目文件
    • MVC应用程序.项目文件.user
    • packages.config
  2. 新建MVC应用程序.项目文件,内容如下:

    <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个作业(job)中会出现以下编译错误:

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

    在ASP.NET项目,添加Microsoft.CSharp作为该项目的参考.但最好将其作为NuGet软件包使用.

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

  3. 调试项目

    你说得对,调试可能会很痛苦.因为VisualStudio不知道它是ASP.NET应用程序,没有启动调试会话的即时方法.

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

    a、 使用IIS Express进行调试.

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

    enter image description here

    对应的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进程来调试应用程序.

这是Sample Project on GitHub美元.它基本上是默认的ASP.NET MVC项目按照上述步骤迁移到新的csproj格式.它可以被编译、执行和调试(包括IIS Express的配置文件)

Asp.net相关问答推荐

Web 部署工具 2.1 和 Web 部署 3.5 有什么区别?从 VS 2010 部署需要哪一个?

创建项目 ASP.NET Core (.NET Core) 和 ASP.NET Core (.NET Framework) 有什么区别

在 appSettings 中存储字符串数组?

有没有办法将 onclick 事件添加到 ASP.NET 标签服务器控件?

在视图 Mvc.net 中访问路由值

我可以在 Visual Studio 2010 中将任务列表项添加到 csHTML 吗?

ASP.NET Web 应用程序消息框

如何在 ASP.NET Web API 中使用非线程安全的 async/await API 和模式?

无法加载文件或程序集'System.Web.WebPages.Razor,版本 = 3.0.0.0

MvcBuildViews true 与 ASP.NET MVC 2 中的实体框架

System.Linq.Dynamic 不支持 OrderByDescending("someColumn")?

免费的 ASP.Net 和/或 CSS 主题

使用 ASPNet_Regiis 加密自定义配置部分 - 你能做到吗?

如何在 ASP.Net 的客户端 (JavaScript) 上判断 Page.Validate()?

ASP.NET MVC Url Route 支持(点)

ASP.NET 发布try 复制不存在的文件

将字典绑定到中继器

如何将我的 Autofac 容器插入 ASP. NET 身份 2.1

IIS 是否执行非法字符替换?如果是这样,如何阻止它?

目录与目录信息