CSHTML

时间:2017-11-16 11:16:34

标签: c# asp.net .net asp.net-mvc roslyn

我的mvc cshtml视图的RenderPartial.ascx

@* Omitted code *@
<div>
    <div class="col-lg-12">
        @{Html.RenderPartial("~/Views/Vacations/_YearPlanner.ascx", ViewData.Model);}
    </div>
</div>
@* Omitted code *@

这一直有效,直到我将Roslyn编译器添加到项目中,因为我想在.cs.cshtml上使用C#6.0。

这让我安装了两个小块:

  

Microsoft.CodeDom.Providers.DotNetCompilerPlatform:1.0.8

     

Microsoft.Net.Compilers:2.3.2(最新版本:2.4.0)

我在安装这些问题时遇到了一些问题,直到我找到正确的版本组合。

但是现在,我正在处理此页面上的一个问题,该问题会导致遗留ascx控件。

  

发生以下错误:       异常类型:HttpCompileException       异常消息:外部组件抛出异常。在System.Web.Compilation.AssemblyBuilder.Compile()at   System.Web.Compilation.BuildProvidersCompiler.PerformBuild()at   System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath   virtualPath)at   System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath   virtualPath,Boolean noBuild,Boolean allowCrossApp,Boolean   allowBuildInPrecompile,Boolean throwIfNotFound,Boolean   保证在最近的时候   System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext的   context,VirtualPath virtualPath,Boolean noBuild,Boolean   allowCrossApp,Boolean allowBuildInPrecompile,Boolean   throwIfNotFound,Boolean ensureIsUpToDate)at   System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath   virtualPath,HttpContext context,Boolean allowCrossApp,Boolean   throwIfNotFound)at   System.Web.Compilation.BuildManager.GetCompiledType(VirtualPath   virtualPath)at   System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext   viewContext,TextWriter writer)at   System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(的HtmlHelper   htmlHelper,String partialViewName,Object model)at   ASP._Views_Vacations_RenderDepartmentMap_cshtml.Execute()at   System.Web.WebPages.WebPageBase.ExecutePageHierarchy()at   System.Web.Mvc.WebViewPage.ExecutePageHierarchy()at   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext   pageContext,TextWriter writer,WebPageRenderingBase startPage)at   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)   在   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList的1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList 1   filters,Int32 filterIndex,ResultExecutingContext preContext,   ControllerContext controllerContext,ActionResult actionResult)at   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList的1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList 1   filters,Int32 filterIndex,ResultExecutingContext preContext,   ControllerContext controllerContext,ActionResult actionResult)at   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList的1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList 1   filters,Int32 filterIndex,ResultExecutingContext preContext,   ControllerContext controllerContext,ActionResult actionResult)at   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList 1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList 1个过滤器,ActionResult actionResult)at   System.Web.Mvc.Async.AsyncControllerActionInvoker&LT;&GT; c__DisplayClass21.b__1e(IAsyncResult的   asyncResult)at   System.Web.Mvc.Controller.b__1d(IAsyncResult的   asyncResult,ExecuteCoreState innerState)at   System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid
1.CallEndDelegate(IAsyncResult的   asyncResult)at   System.Web.Mvc.MvcHandler.b__5(IAsyncResult的   asyncResult,ProcessRequestState innerState)at   System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult的   asyncResult)at   System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()   在System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,   布尔和放大器; completedSynchronously)

当我从webconfig中删除以下行时,此控件开始工作:

<system.codedom>
  <compilers>
    <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
    <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
  </compilers>
</system.codedom>

这是由包Microsoft.CodeDom.Providers.DotNetCompilerPlatform自动添加的。

我需要保留这条线吗?我仍然需要那些C#6.0功能。

我是否需要添加一些内容以使用roslyn编译aspxascx

修改1

它适用于我的机器,但不适用于服务器。

修改2

  
      
  • InnerException - 外部组件抛出异常。
  •   

0 个答案:

没有答案