dotnet CLI和新版vs2017 msbuild之间的关系 [英] Relationship between the dotnet cli and the new vs2017 msbuild

查看:75
本文介绍了dotnet CLI和新版vs2017 msbuild之间的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着VS2017引入的从project.json到新的csproj格式的转换,我努力了解dotnet cli和新的msbuild之间的区别以及何时使用它们之间的区别.

With the move from project.json to the new csproj format introduced with VS2017, I'm struggling to understand the difference between the dotnet cli and the new msbuild and when to use one over the other.

1)要从命令行构建新的csproj netstandard库,我应该调用dotnet cli(例如dotnet restore dotnet build)还是使用msbuild(例如msbuild ExampleNetstandard.sln)

1) To build a new csproj netstandard library from the command line, should I be calling the dotnet cli (for example dotnet restore dotnet build) or use msbuild (for example msbuild ExampleNetstandard.sln).

2)另外,我的理解是,有msbuild的两个版本,一个基于完整框架,另一个针对dotnet core.这样对吗?我是否应该始终使用dotnet version

2) Also, my understanding is that there are two versions of msbuild, one built on the full framework and another targeting dotnet core. Is this correct? Should I always use the dotnet version

3)dotnet cli是独立的还是需要安装msbuild?例如,当您安装dotnet SDK时,是否还会安装msbuild?如果是这样,这是否与vs2017一起安装的版本不同?

3) Is dotnet cli standalone or does it require msbuild to be installed?. For instance when you install the dotnet SDK does this install msbuild as well? If so is this different to the version that is installed with vs2017?

推荐答案

问题

1)要从命令行构建新的csproj netstandard库,我应该调用dotnet cli(例如dotnet restore dotnet build)还是使用msbuild(例如msbuild ExampleNetstandard.sln).

1) To build a new csproj netstandard library from the command line, should I be calling the dotnet cli (for example dotnet restore dotnet build) or use msbuild (for example msbuild ExampleNetstandard.sln).

两个都很好,因为当前dotnet建立在msbuild之上.所以这是一个品味问题.您也可以使用dotnet CLI调用msbuild任务. (dotnet msbuild <msbuild_arguments>)

Both do fine as currently dotnet is built on top of msbuild. So it's a matter of taste. You could also call msbuild tasks by using the dotnet CLI. (dotnet msbuild <msbuild_arguments>)

开始时,所有.NET核心内容仅位于dotnet中,而不位于msbuild中.这很麻烦,因为许多已经构建在msbuild上的东西与dotnet不能很好地配合使用(例如Xamarin).因此,他们将内容移动到了msbuild并在msbuild的顶部构建了dotnet.

In the beginning, all the .NET core stuff was only in dotnet and not in msbuild. This was cumbersome as a lot of stuff that was already built on msbuild wasn't working well with dotnet out of the box (e.g. Xamarin). So they moved the stuff to msbuild and build dotnet on top of msbuild.

dotnet具有msbuild中没有的某些功能,例如dotnet new.我认为dotnetmsbuild更易于使用,因此我更喜欢dotnet.

dotnet has some features that aren't in msbuild, like dotnet new. In my opinion, dotnet is easier to use than msbuild, so I prefer dotnet.

为了更加清楚,我在文章末尾添加了msbuilddotnet之间的比较.

To make it more clear, I have added a comparison between msbuild and dotnet at the end of my post.

2)另外,据我了解,msbuild有两个版本,一个基于完整框架,另一个针对dotnet核心.这样对吗?我是否应该始终使用dotnet版本

2) Also, my understanding is that there are two versions of msbuild, one built on the full framework and another targeting dotnet core. Is this correct? Should I always use the dotnet version

只有一个msbuild. dotnet CLI正在使用msbuild:

There is only one msbuild. dotnet CLI is using msbuild:

由于CLI使用MSBuild作为其构建引擎,因此我们建议将该工具的这些部分编写为自定义MSBuild目标和任务,因为它们随后可以参与整个构建过程

Since CLI uses MSBuild as its build engine, we recommend that these parts of the tool be written as custom MSBuild targets and tasks, since they can then take part in the overall build process

https://docs.microsoft.com/zh-我们/dotnet/articles/core/tools/extensibility

msbuild的旧版本缺少.NET Core支持.也许是其他版本;)

The older version of msbuild was lacking the .NET Core support. Maybe that's the other version ;)

我同意这令人困惑,因为几个月前已经大不相同了.

I agree it's confusing, as it was very different a few months ago.

3)dotnet cli是独立的还是需要安装msbuild?例如,当您安装dotnet SDK时,是否还会安装msbuild?如果是这样,这是否与vs2017一起安装的版本不同?

3) Is dotnet cli standalone or does it require msbuild to be installed?. For instance when you install the dotnet SDK does this install msbuild as well? If so is this different to the version that is installed with vs2017?

我不确定这一点,但是很容易测试.我已经删除了所有的msbuild.exe,它仍然可以正常工作.发现它正在使用SDK文件夹中的msbuild.dll. 例如"C:\ Program Files \ dotnet \ sdk \ 1.0.3 \ MSBuild.dll"

I wasn't sure about this, but it was easy to test. I have removed all msbuild.exe and it still worked. Found out it's using the msbuild.dll in the SDK folder. e.g. "C:\Program Files\dotnet\sdk\1.0.3\MSBuild.dll"

如果将其删除,则有证据:

If you remove that one, there is a proof:

msbuild.dll实际上是msbuild.exe:

msbuild.dll is actually msbuild.exe, as you can see in the properties:

如果查看dotnet CLI的代码,您会发现它正在生成msbuild命令.

If you look into the code of the dotnet CLI, you can see it's generating msbuild commands.

例如dotnet restore,由 RestoreCommand.

For example dotnet restore, is created by the RestoreCommand class inside dotnet CLI.

已剥离的版本:

public class RestoreCommand : MSBuildForwardingApp
{
    ...
    public static RestoreCommand FromArgs(string[] args, string msbuildPath = null)
    {
        var result = parser.ParseFrom("dotnet restore", args);
        ...
        var msbuildArgs = new List<string>
        {
            "/NoLogo",
            "/t:Restore",
            "/ConsoleLoggerParameters:Verbosity=Minimal"
        };
        ...
        return new RestoreCommand(msbuildArgs, msbuildPath);
    }

    public static int Run(string[] args)
    {
        RestoreCommand cmd;
        try
        {
            cmd = FromArgs(args);
        }
        catch (CommandCreationException e)
        {
            return e.ExitCode;
        }

        return cmd.Execute();
    }
    ...
}

您可以看到dotnet restore只是在呼叫msbuild /NoLogo /t:Restore /ConsoleLoggerParameters:Verbosity=Minimal

You can see dotnet restore is just calling msbuild /NoLogo /t:Restore /ConsoleLoggerParameters:Verbosity=Minimal

如果您选中 dotnet v1.0.0 RC2 时,它不是使用msbuild,而是直接调用nuget.

If you check RestoreCommand in the time of dotnet v1.0.0 RC2, it wasn't using msbuild but was calling nuget directly.

return NuGet3.Restore(args, quiet);

dotnetmsbuild

之间的映射

我在dotnetmsbuild之间进行了映射.它还不完整,但是重要的命令在那里.

Mapping between dotnet and msbuild

I made a mapping between dotnet and msbuild. It's not complete, but the important commands are there.

Dotnet                 | Msbuild                                    | Remarks                         
-----------------------|--------------------------------------------|---------------------------------
Add                    |                                            |         
-----------------------|--------------------------------------------|---------------------------------                        
Build                  | /t:Build                                   |  
-----------------------|--------------------------------------------|---------------------------------                                
Build --no-incremental | /t:Rebuild                                 |    
-----------------------|--------------------------------------------|---------------------------------                              
Clean                  | /t:clean                                   |                                 
-----------------------|--------------------------------------------|--------------------------------- 
Complete               |                                            |                                 
-----------------------|--------------------------------------------|--------------------------------- 
Help                   |                                            | Help!                           
-----------------------|--------------------------------------------|--------------------------------- 
List                   |                                            |                                 
-----------------------|--------------------------------------------|--------------------------------- 
Migrate                | -                                          |                                 
-----------------------|--------------------------------------------|--------------------------------- 
Msbuild                |                                            | Forwarding all                  
-----------------------|--------------------------------------------|--------------------------------- 
New                    |                                            |                                 
-----------------------|--------------------------------------------|--------------------------------- 
Nuget                  |                                            |  *
-----------------------|--------------------------------------------|--------------------------------- 
Pack                   | /t:pack                                    |                                 
-----------------------|--------------------------------------------|--------------------------------- 
Publish                | /t:publish                                 |                                 
-----------------------|--------------------------------------------|--------------------------------- 
Remove                 |                                            |                                 
-----------------------|--------------------------------------------|--------------------------------- 
Restore                | /NoLogo /t:Restore                         |
                         /ConsoleLoggerParameters:Verbosity=Minimal |
-----------------------|--------------------------------------------|--------------------------------- 
Run                    | /nologo /verbosity:quiet                   |
                         /p:Configuration=   /p:TargetFramework     |                                 
-----------------------|--------------------------------------------|--------------------------------- 
Sln                    |                                            | Not in msbuild                  
-----------------------|--------------------------------------------|--------------------------------- 
Store                  | /t:ComposeStore                            |                                 
-----------------------|--------------------------------------------|--------------------------------- 
Test                   | /t:VSTest /v:quiet /nologo                 |                                 
-----------------------|--------------------------------------------|--------------------------------- 
Vstest                 |                                            | Forwarding to vstest.console.dll

* dotnet nuget:将软件包添加/删除到csproj,也是nuget.exe的有限集合,请参见

* dotnet nuget: Adding/removing packages to csproj, also limited set of nuget.exe, see comparison

PS SO中没有降价表:(

这篇关于dotnet CLI和新版vs2017 msbuild之间的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆