面向 .NET 4.0 的控制台应用程序中的 Spark
我只是想知道是否有人成功让 Spark 在 .NET 4.0 控制台应用程序中工作以将模板编译为 HTML。不幸的是,我收到以下错误:
Unhandled Exception: Spark.Compiler.CompilerException: Dynamic view compilation failed.
(0,0): error CS1703: An assembly with the same identity 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' has already been imported. Try removing one of the duplicate references.
但是,当我以 .NET 3.5 为目标时,一切正常,但我特别希望以 4.0 为目标。有没有人解决这个问题,Spark 邮件列表上的一些旧线程建议我可能只需要在源代码中编辑一行,然后重新编译,但我希望这是最后的手段。
编辑:
static void Main(string[] args)
{
if (args.Length > 0)
{
var templatePath = Path.Combine(Environment.CurrentDirectory, args[0]);
var templateName = Path.GetFileName(templatePath);
var templateDirPath = Path.GetDirectoryName(templatePath);
var viewFolder = new FileSystemViewFolder(templateDirPath);
var sparkEngine = new SparkViewEngine
{
DefaultPageBaseType = typeof(SparkView).FullName,
ViewFolder = viewFolder.Append(new SubViewFolder(viewFolder, "Shared")),
};
var descriptor = new SparkViewDescriptor().AddTemplate(templateName);
var view = sparkEngine.CreateInstance(descriptor) as SparkView;
view.Model = args[1];
using (var writer = new StreamWriter(new FileStream(args[2], FileMode.Create), Encoding.UTF8))
{
view.RenderView(writer);
}
}
else
{
Console.WriteLine(">>> error - missing arguments:\n\tSparkCompiler.exe [templatepath] [modelstring] [outputname]");
}
}
I was just wondering if anyone has successfully got Spark to work in a .NET 4.0 console application for compiling templates to HTML. Unfortunately I am getting the following error:
Unhandled Exception: Spark.Compiler.CompilerException: Dynamic view compilation failed.
(0,0): error CS1703: An assembly with the same identity 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' has already been imported. Try removing one of the duplicate references.
However, when I target .NET 3.5 everything works fine, however I specifically wish to target 4.0. Has anyone solved this problem, some old threads on the Spark mailing list suggest I may just have to edit a line in the source, and recompile, but I hope this is a last resort.
EDIT:
static void Main(string[] args)
{
if (args.Length > 0)
{
var templatePath = Path.Combine(Environment.CurrentDirectory, args[0]);
var templateName = Path.GetFileName(templatePath);
var templateDirPath = Path.GetDirectoryName(templatePath);
var viewFolder = new FileSystemViewFolder(templateDirPath);
var sparkEngine = new SparkViewEngine
{
DefaultPageBaseType = typeof(SparkView).FullName,
ViewFolder = viewFolder.Append(new SubViewFolder(viewFolder, "Shared")),
};
var descriptor = new SparkViewDescriptor().AddTemplate(templateName);
var view = sparkEngine.CreateInstance(descriptor) as SparkView;
view.Model = args[1];
using (var writer = new StreamWriter(new FileStream(args[2], FileMode.Create), Encoding.UTF8))
{
view.RenderView(writer);
}
}
else
{
Console.WriteLine(">>> error - missing arguments:\n\tSparkCompiler.exe [templatepath] [modelstring] [outputname]");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
现已将针对此问题的修复添加到主 Spark master 分支中。您可以下载源代码并编译最新的二进制文件,也可以使用 NuPack/NuGet 在 VS2010 中添加对您的解决方案的引用,因为从现在起,那里的二进制文件将保持最新。
希望有帮助...
A fix for this has now been added to the main Spark master branch. You can either download the source and compile the latest binaries, or you can also use NuPack/NuGet to add a reference to your solution in VS2010 as the binaries there will be kept up to date from now on.
Hope that helps...
我不认为这是最后的手段。我将 src\Spark\Compiler\BatchCompiler.cs 的第 60 行更改为
原来的行。
在重新编译并引用新的 Spark.dll 之后,一切都像魅力一样工作。呃,嗯,我能够继续处理下一个异常。
I didn't consider it a last resort. I changed Line #60 of src\Spark\Compiler\BatchCompiler.cs to
it was originally
After a recompile and referencing the new Spark.dll everything worked like a charm. er, um, i was able to proceed to the next exception.