面向 .NET 4.0 的控制台应用程序中的 Spark

发布于 2024-09-18 05:24:58 字数 1715 浏览 1 评论 0原文

我只是想知道是否有人成功让 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

水水月牙 2024-09-25 05:24:58

现已将针对此问题的修复添加到主 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...

辞旧 2024-09-25 05:24:58

我不认为这是最后的手段。我将 src\Spark\Compiler\BatchCompiler.cs 的第 60 行更改为

var providerOptions = new Dictionary { { "CompilerVersion", "v4.0" } };

原来的行。

var providerOptions = new Dictionary { { "CompilerVersion", "v3.5" } };

在重新编译并引用新的 Spark.dll 之后,一切都像魅力一样工作。呃,嗯,我能够继续处理下一个异常。

I didn't consider it a last resort. I changed Line #60 of src\Spark\Compiler\BatchCompiler.cs to

var providerOptions = new Dictionary { { "CompilerVersion", "v4.0" } };

it was originally

var providerOptions = new Dictionary { { "CompilerVersion", "v3.5" } };

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文