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?
Haben Sie versucht, zuerst die Pakete wiederherzustellen (via DNU Restore IIRC)? –
@MartinKlinke ja ich habe, sowohl innerhalb VS als auch mit dem CLI (das ist derzeit dotnet wiederherstellen), aber danke für den Vorschlag. –