繁体   English   中英

为什么剃须刀在Visual Studio中工作而不在exe外部工作?

[英]Why is razor working in visual studio and not outside in the exe?

好,所以我有这个模板

<h2 style="margin-bottom:2px;">Missing Files</h2>
@if(@Model.m.Count > 0){
  <h4>Found @Model.m.Count missing file(s) from the pool folder</h4> 
  @foreach(var item in @Model.m)
  {
    <p class="alert alert-error">@item</p>
  }
}else{
  <h4 class="alert alert-success">Nothing missing from the pool folder.</h4> 
}

<h2 style="margin-bottom:2px;">Wrong Sizes</h2>
@if(@Model.w.Count > 0){
  <h4>Found @Model.w.Count file(s) with the wrong size.</h4> 
  @foreach(var item in @Model.m)
  {
    <p class="alert alert-error">@item</p>
  }
}else{
  <h4 class="alert alert-success">No files have the wrong size</h4> 
}

当我构建代码时效果很好,但是当我进入调试目录并尝试运行生成的.exe时,我得到了

: Unable to compile template. Check the Errors list for details.
   at RazorEngine.Compilation.DirectCompilerServiceBase.CompileType(TypeContext context)
   at RazorEngine.Templating.TemplateService.CreateTemplate(String template, Type modelType)
   at RazorEngine.Templating.TemplateService.GetTemplate(String template, Type modelType, String name)
   at RazorEngine.Templating.TemplateService.Parse[T](String template, T model, String name)
   at RazorEngine.Razor.Parse[T](String template, T model, String name)
   at syncspec.Form1.btnBrowse_Click_1(Object sender, EventArgs e) in C:\Users\Matt\Documents\Visual Studio 2010\Projects\moodmedia\moodmedia\Form1.cs:line 93
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.239 (RTMGDR.030319-2300)
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------

任何想法,我想念的是什么,为什么它不能在Visual Studio 2010中工作,而不能通过单击exe来调试调试

UPDATE

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using syncspec;
using System.Net;
using System.IO;
using System.Xml;
using System.Web.Razor;
using RazorEngine;
using RazorEngine.Templating;


            string route = @"C:\testing\test.html";
            string template = System.IO.File.ReadAllText("template.html");

            FileStream fs = new FileStream(route, FileMode.Create);
            using (StreamWriter outfile = new StreamWriter(fs))
            {

                string result = Razor.Parse(template, new {m = missing, w = wrongSizes});
                outfile.Write(result);

仅供参考-大小缺失都是列表

我曾经在网上搜索托管剃刀的模板机制。 这并不明显,而且很努力。 我知道的最好的文章之一是:

http://www.west-wind.com/weblog/posts/2010/Dec/27/Hosting-the-Razor-Engine-for-Templating-in-NonWeb-Applications

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM