2016-05-10 12 views
1

project.json構造の単純な.NetコンソールアプリケーションをVS2015オプションのConsole Application(Package)を使用して作成しようとしています。外部のNuGetパッケージ、および私は参照エラーを取得しています。。project.jsonを使用した.NETコンソールアプリケーション:タイプが参照されていないアセンブリに定義されています

の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" 
     } 
    } 
    } 
} 

とエラー:

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'. 

私はproject.jsonせずに、 "伝統的な" コンソールアプリケーションを作成した場合まったく同じProgram.csコードを使用して正常に動作します。

環境:

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

編集:私はパッケージを復元し、クリーン/再構築、そしてまた一からプロジェクトを作成しようとしたが、それらは助けにはなりませんでした。

私は何か間違っているのですか、これはバグですか?

+0

dnu restore IIRCを使用してパッケージを最初に復元しようとしましたか? –

+0

@MartinKlinkeはい私はVS内でもCLI(現時点ではドットネットのリストア)でも行っていますが、提案に感謝します。 –

答えて

1

私は解決策を見つけました。私はframeworkAssembliesの中にSystem.Runtimeを追加しなければなりません。作業中のプロジェクト.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" 
     } 
    } 
    } 
} 
関連する問題