Visual studio 2017 dotnet构建没有显示visualstuio所显示的StyleCop警告

Visual studio 2017 dotnet构建没有显示visualstuio所显示的StyleCop警告,visual-studio-2017,roslyn,stylecop,dotnet-cli,Visual Studio 2017,Roslyn,Stylecop,Dotnet Cli,我创建了一个小项目并添加了这个包(基于Roslyn)。当我在VisualStudio中构建时,我可以看到一些警告,这正是我所期望的 但是,当我使用dotnetcli(dotnetbuild)构建它时,没有收到任何警告。为了确保这一点,我还尝试使用了msbuild,但也没有产生任何警告: 因此,我想知道:这两种方法有什么区别?如何才能获得相同的结果?这是因为警告不会阻止生成程序集。Visual Studio已生成程序集,因此当您调用dotnet build或msbuild时,两者都会看到没有更改

我创建了一个小项目并添加了这个包(基于Roslyn)。当我在VisualStudio中构建时,我可以看到一些警告,这正是我所期望的

但是,当我使用dotnetcli(
dotnetbuild
)构建它时,没有收到任何警告。为了确保这一点,我还尝试使用了
msbuild
,但也没有产生任何警告:


因此,我想知道:这两种方法有什么区别?如何才能获得相同的结果?

这是因为警告不会阻止生成程序集。Visual Studio已生成程序集,因此当您调用
dotnet build
msbuild
时,两者都会看到没有更改,并且不会执行生成。如果运行
msbuild/t:rebuild
(运行重建目标),您将在命令行上看到警告

以下是使用Visual Studio 2017.6和dotnet core 2.0在我的机器上发生的情况:

C:\>dotnet new console -n stylcoptest
The template "Console Application" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on stylcoptest\stylcoptest.csproj...
  Restoring packages for C:\stylcoptest\stylcoptest.csproj...
  Generating MSBuild file C:\stylcoptest\obj\stylcoptest.csproj.nuget.g.props.
  Generating MSBuild file C:\stylcoptest\obj\stylcoptest.csproj.nuget.g.targets.
  Restore completed in 192.26 ms for C:\stylcoptest\stylcoptest.csproj.

Restore succeeded.

C:\>cd stylcoptest

>dotnet add package StyleCop.Analyzers --version 1.1.0-beta006
info : Adding PackageReference for package 'StyleCop.Analyzers' into project 'C:\stylcoptest\stylcoptest.csproj'
log  : Restoring packages for C:\stylcoptest\stylcoptest.csproj...
log  : Installing StyleCop.Analyzers 1.1.0-beta006.
info : Package 'StyleCop.Analyzers' is compatible with all the specified frameworks in project 'C:\stylcoptest\stylcoptest.csproj'
info : PackageReference for package 'StyleCop.Analyzers' version '1.1.0-beta006' added to file 'C:\stylcoptest\stylcoptest.csproj'

C:\stylcoptest> dotnet build
Microsoft (R) Build Engine version 15.7.163.20755 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 41.27 ms for C:\stylcoptest\stylcoptest.csproj.
Program.cs(1,1): warning SA1633: The file header is missing or not located at the top of the file. [C:\stylcoptest\stylcoptest.csproj]
Program.cs(3,11): warning SA1300: Element 'stylcoptest' should begin with an uppercase letter [C:\stylcoptest\stylcoptest.csproj]
Program.cs(1,1): warning SA1200: Using directive should appear within a namespace declaration [C:\stylcoptest\stylcoptest.csproj]
Program.cs(5,11): warning SA1400: Element 'Program' should declare an access modifier [C:\stylcoptest\stylcoptest.csproj]
Program.cs(7,21): warning SA1400: Element 'Main' should declare an access modifier [C:\stylcoptest\stylcoptest.csproj]
CSC : warning SA0001: XML comment analysis is disabled due to project configuration [C:\stylcoptest\stylcoptest.csproj]
  stylcoptest -> C:\Users\marol\Downloads\stylcoptest\bin\Debug\netcoreapp2.0\stylcoptest.dll

Build succeeded.

Program.cs(1,1): warning SA1633: The file header is missing or not located at the top of the file. [C:\stylcoptest\stylcoptest.csproj]
Program.cs(3,11): warning SA1300: Element 'stylcoptest' should begin with an uppercase letter [C:\stylcoptest\stylcoptest.csproj]
Program.cs(1,1): warning SA1200: Using directive should appear within a namespace declaration [C:\stylcoptest\stylcoptest.csproj]
Program.cs(5,11): warning SA1400: Element 'Program' should declare an access modifier [C:\stylcoptest\stylcoptest.csproj]
Program.cs(7,21): warning SA1400: Element 'Main' should declare an access modifier [C:\stylcoptest\stylcoptest.csproj]
CSC : warning SA0001: XML comment analysis is disabled due to project configuration [C:\stylcoptest\stylcoptest.csproj]
    6 Warning(s)
    0 Error(s)

Time Elapsed 00:00:03.84

C:\stylcoptest>msbuild /m /v:m
Microsoft (R) Build Engine version 15.6.85.37198 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

  stylcoptest -> C:\stylcoptest\bin\Debug\netcoreapp2.0\stylcoptest.dl

C:\stylcoptest>msbuild /m /v:m /t:rebuild
Microsoft (R) Build Engine version 15.6.85.37198 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Program.cs(1,1): warning SA1633: The file header is missing or not located at the top of the file. [C:\stylcoptest\stylcoptest.csproj]
Program.cs(1,1): warning SA1200: Using directive should appear within a namespace declaration [C:\stylcoptest\stylcoptest.csproj]
Program.cs(5,11): warning SA1400: Element 'Program' should declare an access modifier [C:\stylcoptest\stylcoptest.csproj]
Program.cs(3,11): warning SA1300: Element 'stylcoptest' should begin with an uppercase letter [C:\stylcoptest\stylcoptest.csproj]
Program.cs(7,21): warning SA1400: Element 'Main' should declare an access modifier [C:\stylcoptest\stylcoptest.csproj]
CSC : warning SA0001: XML comment analysis is disabled due to project configuration [C:\stylcoptest\stylcoptest.csproj]
  stylcoptest -> C:\stylcoptest\bin\Debug\netcoreapp2.0\stylcoptest.dll