Pau*_*ner 27 asp.net csproj asp.net-core-2.0
新的.csproj格式包括对经典文件的一些重大改进,包括与NuGet包管理的紧密集成以及明显不那么冗长的结构.我希望在使用.NET Framework 4.6和ASP.NET的同时获得这些好处(因为我的项目依赖于尚未生成.NET Core版本的Umbraco).
最大的挑战似乎是调试体验 - ASP.NET Core项目期望运行dotnet核心应用程序并为IIS实例设置反向代理.这个过程与.NET Framework模型完全不同,我不知道从哪里开始尝试在Visual Studio中设置调试.
有没有办法让这两个项目模型混合使用?
Cod*_*ler 52
关于支持ASP.NET(非核心)应用程序的新csproj格式,GitHub上存在许多未解决的问题.他们中有一些:
您可能已经了解,ASP.NET应用程序尚不支持新的csproj格式.它可以使它工作,但它不会很顺利.
前段时间我尝试用新的csproj格式创建ASP.NET MVC项目,只是为了好玩.我做到了,但我没有玩过很多次.知道你的经历会很有趣.
步骤如下:
删除旧的不需要的项目文件:
使用以下内容创建新的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>
Run Code Online (Sandbox Code Playgroud)
上面的长包列表包含为默认ASP.NET MVC应用程序添加的默认包.您应该添加应用程序使用的其他包.
不要忘记添加Microsoft.CSharp包,否则您将在ViewBag分配时遇到以下编译错误:
错误CS0656:缺少编译器所需的成员'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'
在ASP.NET项目中,Microsoft.CSharp添加为项目的参考.但最好将它作为NuGet包使用.
唯一无法避免的直接参考是a System.Web.
调试项目
当你说调试可能很痛苦时,你是对的.由于Visual Studio不知道它是一个ASP.NET应用程序,因此没有即时方法来启动调试会话.
我在这里看到两种可能的解决方
一个.使用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"
}
}
Run Code Online (Sandbox Code Playgroud)
湾 使用IIS进行调试.
在IIS管理器中,创建指向项目目录的应用程序.现在,您可以通过附加到w3wp.exe流程来调试应用程序.
这是GitHub上的示例项目.它基本上是默认的ASP.NET MVC项目,按照上述步骤迁移到新的csproj格式.它可以编译,执行和调试(包括IIS Express的配置文件)
我正在关注有关此问题的 github 问题,并且发布的最新评论添加了最后缺失的部分。基本上,使用这样的 .csproj 文件:
<Project>
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
<PropertyGroup>
<OutputType>Library</OutputType>
<OutputPath>bin\</OutputPath>
<TargetFramework>net48</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<PublishProfileImported>true</PublishProfileImported>
</PropertyGroup>
<ItemGroup>
<ProjectCapability Include="DotNetCoreWeb" />
<ProjectCapability Include="SupportsSystemWeb" />
</ItemGroup>
<!-- add your packagereference/content/etc includes here -->
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<!-- order is important! -->
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" />
</Project>
Run Code Online (Sandbox Code Playgroud)
一切正常!
似乎仍然缺少的唯一一件事是右键单击部署功能......但是当你可以msbuild /p:DeployOnBuild=True用来部署时,我终于看不到任何阻止我升级的东西了。
| 归档时间: |
|
| 查看次数: |
6275 次 |
| 最近记录: |