2016-05-10 5 views
1

Ich versuche, eine einfache .Net-Konsole-Anwendung mit Projekt.json Struktur zu erstellen, die VS2015-Option Konsole Anwendung (Paket) verwenden ein externes NuGet-Paket, und ich bekomme Referenzfehler..Net-Konsolenanwendung mit project.json: Typ ist in einer Assembly definiert, die nicht referenziert

Program.cs:

using System.Net.Http; 
using System.Threading.Tasks; 
using Nito.AsyncEx; 

namespace AsyncTest 
{ 
    public class Program 
    { 
     public static void Main(string[] args) 
     { 
      AsyncContext.Run(() => MainAsync(args)); 
     } 

     public static async void MainAsync(string[] args) 
     { 
      var urlContents = await AccessTheWebAsync(); 
     } 

     static async Task<int> AccessTheWebAsync() 
     { 
      HttpClient client = new HttpClient(); 

      Task<string> getStringTask = client.GetStringAsync("http://msdn.microsoft.com"); 

      string urlContents = await getStringTask; 

      return urlContents.Length; 
     } 

    } 
} 

project.json:

{ 
    "version": "1.0.0-*", 
    "description": "AsyncTest Console Application", 
    "authors": [ "ricsmania" ], 
    "tags": [ "" ], 
    "projectUrl": "", 
    "licenseUrl": "", 

    "compilationOptions": { 
    "emitEntryPoint": true 
    }, 

    "dependencies": { 
    "Nito.AsyncEx": "3.0.1" 
    }, 

    "commands": { 
    "AsyncTest": "AsyncTest" 
    }, 

    "frameworks": { 
    "dnx451": { 
     "dependencies": { 
     "Microsoft.Net.Http": "2.2.22", 
     "System.Runtime": "4.0.0" 
     } 
    } 
    } 
} 

Und die Fehler:

DNX 4.5.1 error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 
DNX 4.5.1 error CS0012: The type 'Action' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 
DNX 4.5.1 error CS0012: The type 'Func<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 

Wenn ich eine "traditionelle" Konsole-Anwendung ohne project.json erstellen mit dem gleichen Code Program.cs funktioniert es gut.

Umwelt:

Windows 10 Pro 
Visual Studio 2015 Professional 14.0.25123.00 Update 2 
.Net 4.6.1 
DNX 1.0.0-rc2-20221 

EDIT: Ich habe versucht, Pakete wiederherzustellen und sauber/neu zu erstellen, und auch ein Projekt von Grund auf neu erstellen, aber die helfen nicht.

Mache ich etwas falsch oder ist das ein Fehler?

+0

Haben Sie versucht, zuerst die Pakete wiederherzustellen (via DNU Restore IIRC)? –

+0

@MartinKlinke ja ich habe, sowohl innerhalb VS als auch mit dem CLI (das ist derzeit dotnet wiederherstellen), aber danke für den Vorschlag. –

Antwort

1

Ich fand die Lösung. Ich musste System.Runtime innerhalb von FrameworkAssemblies hinzufügen, nicht von Abhängigkeiten. Working project.json:

{ 
    "version": "1.0.0-*", 
    "description": "AsyncTest Console Application", 
    "authors": [ "ricardo.smania" ], 
    "tags": [ "" ], 
    "projectUrl": "", 
    "licenseUrl": "", 

    "compilationOptions": { 
    "emitEntryPoint": true 
    }, 

    "dependencies": { 
    "Nito.AsyncEx": "3.0.1" 
    }, 

    "commands": { 
    "AsyncTest": "AsyncTest" 
    }, 

    "frameworks": { 
    "dnx451": { 
     "dependencies": { 
     "Microsoft.Net.Http": "2.2.22" 
     }, 
     "frameworkAssemblies": {   
     "System.Runtime": "4.0.0.0", 
     "System.Threading.Tasks": "4.0.0.0" 
     } 
    } 
    } 
} 
Verwandte Themen