2016-08-01 154 views
1

我學習dotnet CLI(以及.NET核心)和一件事關於多平臺定位不明確。假設我的項目有以下部分:.NET核心CLI運行非核心應用程序,它是如何工作的?

"frameworks": { 
    "netcoreapp1.0": { 
     ... 
    }, 
    "net451": { } 
    } 

而且我的電腦上安裝了net451。然後我運行它:

dotnet run -f net451 

什麼是用來編譯和運行項目?它是否從net451 sdk調用msbuild?運行的應用程序可以仍然被視爲.NET核心應用程序?

一些有用的鏈接:

Running .NET Core apps on multiple frameworks and What the Target Framework Monikers (TFMs) are about

+0

不要潛水太深。微軟仍在改變它,MSBuild將回歸。 –

+0

對,這是我的問題,我不能使用工具,直到我知道它是如何工作的...我試圖克服它。 – neleus

回答

1

什麼是用來編譯和運行項目?它是否從net451 sdk調用msbuild?

你可以找到自己,如果你添加-v標誌dotnet

> dotnet -v run -f net451 

Project hwapp (.NETFramework,Version=v4.5.1) will be compiled because expected outputs are missing 
     C:\code\hwapp\bin\Debug\net451\rtmapp.exe 
     C:\code\hwapp\bin\Debug\net451\rtmapp.pdb 
     C:\code\hwapp\bin\Debug\net451\win7-x64\rtmapp.exe 
     C:\code\hwapp\bin\Debug\net451\win7-x64\rtmapp.pdb 
Compiling hwapp for .NETFramework,Version=v4.5.1 
Running C:\Program Files\dotnet\dotnet.exe "C:\Program Files\dotnet\sdk\1.0.0-preview2-003121\csc.dll" -noconfig @C:\code\hwapp\obj\Debug\net451\dotnet-compile-csc.rsp 
Process ID: 4900 

Compilation succeeded. 
    0 Warning(s) 
    0 Error(s) 

Time elapsed 00:00:01.4136972 


Running C:\code\hwapp\bin\Debug\net451\win7-x64\rtmapp.exe 
Process ID: 12208 
Hello World! 

> dotnet -v run -f netcoreapp1.0 

Project hwapp (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing 
     C:\code\hwapp\bin\Debug\netcoreapp1.0\rtmapp.dll 
     C:\code\hwapp\bin\Debug\netcoreapp1.0\rtmapp.pdb 
     C:\code\hwapp\bin\Debug\netcoreapp1.0\rtmapp.deps.json 
     C:\code\hwapp\bin\Debug\netcoreapp1.0\rtmapp.runtimeconfig.json 
Compiling hwapp for .NETCoreApp,Version=v1.0 
Running C:\Program Files\dotnet\dotnet.exe "C:\Program Files\dotnet\sdk\1.0.0-preview2-003121\csc.dll" -noconfig @C:\code\hwapp\obj\Debug\netcoreapp1.0\dotnet-compile-csc.rsp 
Process ID: 12084 

Compilation succeeded. 
    0 Warning(s) 
    0 Error(s) 

Time elapsed 00:00:01.6766971 


Running C:\Program Files\dotnet\dotnet.exe exec --additionalprobingpath C:\Users\Svick\.nuget\packages C:\code\hwapp\bin\Debug\netcoreapp1.0\rtmapp.dll 
Process ID: 9068 
Hello World! 

注意,在這兩種情況下,中信建投,C#編譯器,直接使用(它是對.NET核心版本的csc,所以它使用dotnet csc.dll運行)。兩者之間的主要區別是.rsp文件,其中包含csc的其他參數。

net451版本,它的有趣的部分是這樣的:

-out:"C:\code\hwapp\bin\Debug\net451\hwapp.exe" 
-r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\mscorlib.dll" 
-r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.dll" 
-r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Core.dll" 
-r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\Microsoft.CSharp.dll" 

這意味着什麼,用net451:該引用組件的.Net框架4.5.1用於編譯應用程序。

netcoreapp1.0版本,它看起來像這樣(截斷):

-out:"C:\code\hwapp\bin\Debug\netcoreapp1.0\hwapp.dll" 
-r:"C:\Users\Svick\.nuget\packages\Microsoft.CSharp\4.0.1\ref\netstandard1.0\Microsoft.CSharp.dll" 
-r:"C:\Users\Svick\.nuget\packages\Microsoft.VisualBasic\10.0.1\ref\netstandard1.1\Microsoft.VisualBasic.dll" 
-r:"C:\Users\Svick\.nuget\packages\Microsoft.Win32.Primitives\4.0.1\ref\netstandard1.3\Microsoft.Win32.Primitives.dll" 
-r:"C:\Users\Svick\.nuget\packages\System.AppContext\4.1.0\ref\netstandard1.6\System.AppContext.dll" 
-r:"C:\Users\Svick\.nuget\packages\System.Buffers\4.0.0\lib\netstandard1.1\System.Buffers.dll" 
-r:"C:\Users\Svick\.nuget\packages\System.Collections\4.0.11\ref\netstandard1.3\System.Collections.dll" 
-r:"C:\Users\Svick\.nuget\packages\System.Collections.Concurrent\4.0.12\ref\netstandard1.3\System.Collections.Concurrent.dll" 

注意.Net Standard Library參考組件代替。

在任一種情況下,是的msbuild根本不使用。

可以運行的應用程序仍然被認爲是.NET核心應用?

我不這麼認爲。我會說這是一個.Net Framework應用程序,使用.Net Core CLI/SDK創建。是的,這很混亂。

+0

這正是我正在尋找的!謝謝。所以舊的.net的主要區別是編譯如何執行,csc.dll vs msbuild。現在,當微軟承諾將其帶回,我想會有編制的兩種方式:) – neleus

+1

@neleus沒了,除非我誤解了他們。當MSBuild返回時,所有內容都將更改爲基於MSBuild。 –

相關問題