.NET Core CLI运行非核心应用程序,它是如何工作的?

时间:2016-08-01 09:20:28

标签: .net multiplatform .net-core

我正在学习dotnet CLI(以及.NET Core),有一点不清楚多平台定位。假设我的项目有以下部分:

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

我的电脑上安装了net451。然后我运行它:

dotnet run -f net451

用于编译和运行项目的内容是什么?它是否从net451 sdk调用msbuild?运行的应用程序是否仍可被视为.NET Core App?

一些有用的链接:

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

1 个答案:

答案 0 :(得分: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!

请注意,在这两种情况下,直接使用csc(C#编译器)(它是csc的.Net Core版本,因此它使用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 Framework 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 Core App?

我不这么认为。我说这是一个.Net Framework应用程序,使用.Net Core CLI / SDK创建。是的,这令人困惑。