为什么 ASP.NET vNext 'dnu build' 在 OSX 上不起作用

Why is ASP.NET vNext 'dnu build' not working on OSX

按照 https://github.com/aspnet/Home 的指示在 OSX 上安装了 DNVM 和 DNX。

我使用 generator-aspnet 创建了一个包含一个源文件的控制台应用程序,Program.cs:

using System;

namespace HelloWorldConsole
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World");
            Console.ReadLine();
        }
    }
}

和一个package.json:

{
    "version": "1.0.0-*",
    "dependencies": {},
    "commands": {
        "run": "run"
    },
    "frameworks": {
        "dnx451": {},
        "dnxcore50": {
            "dependencies": {
                "System.Console": "4.0.0-beta-*"
            }
        }
    }
}

当我 运行 它使用 dnu . run 时,它按预期工作并打印 "Hello World!"。

然而,当我尝试通过 运行ning dnu build 从它生成程序集时,我收到以下错误:

System.IO.EndOfStreamException: Failed to read past end of stream.
at System.IO.BinaryReader.ReadChar () [0x00000] in :0 at Microsoft.CodeAnalysis.CvtResFile.ReadStringOrID (System.IO.BinaryReader fhIn) [0x00000] in :0 at Microsoft.CodeAnalysis.CvtResFile.ReadResFile (System.IO.Stream stream) [0x00000] in :0 at Microsoft.CodeAnalysis.Compilation.MakeWin32ResourceList (System.IO.Stream win32Resources, Microsoft.CodeAnalysis.DiagnosticBag diagnostics) [0x00000] in :0 at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.SetupWin32Resources (Microsoft.CodeAnalysis.CSharp.Emit.PEModuleBuilder moduleBeingBuilt, System.IO.Stream win32Resources, Microsoft.CodeAnalysis.DiagnosticBag diagnostics) [0x00000] in :0 at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.CompileImpl (Microsoft.CodeAnalysis.Emit.CommonPEModuleBuilder moduleBuilder, System.IO.Stream win32Resources, System.IO.Stream xmlDocStream, Boolean generateDebugInfo, Microsoft.CodeAnalysis.DiagnosticBag diagnostics, System.Predicate1 filterOpt, CancellationToken cancellationToken) [0x00000] in <filename unknown>:0 at Microsoft.CodeAnalysis.Compilation.Compile (Microsoft.CodeAnalysis.Emit.CommonPEModuleBuilder moduleBuilder, System.IO.Stream win32Resources, System.IO.Stream xmlDocStream, Boolean generateDebugInfo, Microsoft.CodeAnalysis.DiagnosticBag diagnostics, System.Predicate1 filterOpt, CancellationToken cancellationToken) [0x00000] in :0 at Microsoft.CodeAnalysis.Compilation.Emit (Microsoft.CodeAnalysis.EmitStreamProvider peStreamProvider, Microsoft.CodeAnalysis.EmitStreamProvider pdbStreamProvider, Microsoft.CodeAnalysis.EmitStreamProvider xmlDocumentationStreamProvider, Microsoft.CodeAnalysis.EmitStreamProvider win32ResourcesStreamProvider, IEnumerable1 manifestResources, Microsoft.CodeAnalysis.Emit.EmitOptions options, Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData, System.Func1 getHostDiagnostics, CancellationToken cancellationToken) [0x00000] in :0 at Microsoft.CodeAnalysis.Compilation.Emit (System.IO.Stream peStream, System.IO.Stream pdbStream, System.IO.Stream xmlDocumentationStream, System.IO.Stream win32Resources, IEnumerable1 manifestResources, Microsoft.CodeAnalysis.Emit.EmitOptions options, Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData, System.Func1 getHostDiagnostics, CancellationToken cancellationToken) [0x00000] in :0 at Microsoft.CodeAnalysis.Compilation.Emit (System.IO.Stream peStream, System.IO.Stream pdbStream, System.IO.Stream xmlDocumentationStream, System.IO.Stream win32Resources, IEnumerable1 manifestResources, Microsoft.CodeAnalysis.Emit.EmitOptions options, CancellationToken cancellationToken) [0x00000] in <filename unknown>:0 at Microsoft.Framework.Runtime.Roslyn.RoslynProjectReference.EmitAssembly (System.String outputPath) [0x00000] in <filename unknown>:0 at Microsoft.Framework.PackageManager.ProjectBuilder.Build (System.String name, System.String outputPath) [0x00000] in <filename unknown>:0<br> at Microsoft.Framework.PackageManager.BuildContext.Build (System.Collections.Generic.List1 diagnostics) [0x00000] in :0 at Microsoft.Framework.PackageManager.BuildManager.Build () [0x00000] in :0 at Microsoft.Framework.PackageManager.Program+<>c__DisplayClass3_4.b__8 () [0x00000] in :0 at Microsoft.Framework.Runtime.Common.CommandLine.CommandLineApplication.Execute (System.String[] args) [0x00000] in :0 at Microsoft.Framework.PackageManager.Program.Main (System.String[] args) [0x00000] in :0 at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0

知道为什么 dnx 。 运行 有效但 dnu build 无效?核心库似乎正在被引用和加载,因此 运行 正常工作。 dnu 构建命令缺少什么?

这是一个已知的 Mono 错误:https://bugzilla.xamarin.com/show_bug.cgi?id=29499

讨论在这里:https://github.com/aspnet/Home/issues/498

我做的是这样的:

  1. 克隆 mono 存储库,按照此处的说明编译并安装它 http://www.mono-project.com/docs/compiling-mono/(确保遵循从 git 源代码编译的说明)
  2. 酿造水龙头aspnet/dnx
  3. 酿造升级
  4. brew install dnvm --without-mono

完成此操作后,我能够 运行 dnu 构建成功。

问题似乎是 brew 指向一个版本的 mono,它似乎不能很好地与 aspnet/dnx 的最新版本一起工作。这是让它指向一个可行版本的方法。

  1. 纳米/usr/local/Library/Formula/mono.rb
  2. 将第 4 行和第 5 行更改为

    url "http://download.mono-project.com/sources/mono/mono-4.0.1.44.tar.bz2" sha256 "eaf5bd9d19818cb89483b3c9cae2ee3569643fd621560da036f6a49f6b3e3a6f"

  3. brew 升级单声道

  4. 您应该能够在项目

    上正确 运行 dnu 构建
    • 来源dnvm.sh
    • cd projectdir
    • dnu 恢复
    • dnu 构建
    • export MONO_MANAGED_WATCHER=false(对于单声道错误,请参阅下面的 link)
    • dnx。红隼
    • 打开http://localhost:5001

关于单声道错误 -

如果你在使用 brew 时遇到问题,请使用 brew doctor

感谢 salerth https://github.com/aspnet/Home/issues/498