Build w/ VS 2019; restore w/ `msbuild` (#375)

- handle both SDK-style and legacy projects in one way
  - set `$(RestorePackagesConfig)` to cover both project types
- allow newer .NET SDKs to align w/ VS components
- make a few `<import/>`s conditional to avoid problems in `Restore` target evaluation
- restore global packages.config before building to make StyleCop available
- move second copies of packages.config packages into packages/ folder
- update FxCop TFM
  - .NET 4.0 not supported because current FxCopSdk is built against .NET 4.7.2
- suppress new warnings about old FxCop approach and not using `IFormatProvider`
This commit is contained in:
Doug Bunting 2022-12-12 11:16:33 -08:00 коммит произвёл GitHub
Родитель feb9b134b0
Коммит c98af896fc
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
12 изменённых файлов: 65 добавлений и 51 удалений

Просмотреть файл

@ -43,7 +43,7 @@ jobs:
displayName: CodeQL
pool:
name: NetCore1ESPool-Internal
demands: ImageOverride -equals windows.vs2017.amd64
demands: ImageOverride -equals windows.vs2019.amd64
timeoutInMinutes: 90
steps:

Просмотреть файл

@ -3,6 +3,11 @@
<PropertyGroup>
<!-- Require VS2017 so VS builds also use MSBuild v15.0. -->
<MinimumVisualStudioVersion>15.0</MinimumVisualStudioVersion>
<MinimumVisualStudioVersion>16.0</MinimumVisualStudioVersion>
<!--
Suppress "MSBUILD : warning : Post-build Code Analysis (FxCopCmd.exe) has been deprecated in favor of FxCop
analyzers, which run during build. Refer to https://aka.ms/fxcopanalyzers to migrate to FxCop analyzers."
-->
<SuppressLegacyCodeAnalysisDeprecatedWarning>true</SuppressLegacyCodeAnalysisDeprecatedWarning>
</PropertyGroup>
</Project>

Просмотреть файл

@ -11,6 +11,7 @@
<BuildPortable Condition=" '$(BuildPortable)' == '' ">true</BuildPortable>
<BuildInParallel Condition=" '$(BuildInParallel)' == '' And $(MSBuildNodeCount) &gt; 1 ">true</BuildInParallel>
<BuildInParallel Condition=" '$(BuildInParallel)' == '' ">false</BuildInParallel>
<RestoreInParallel Condition=" '$(RestoreInParallel)' == '' ">false</RestoreInParallel>
<TestInParallel Condition=" '$(TestInParallel)' == '' ">false</TestInParallel>
<TestResultsDirectory>$(MSBuildThisFileDirectory)bin\$(Configuration)\test\TestResults\</TestResultsDirectory>
<SkipStrongNamesExe>$(MSBuildThisFileDirectory)packages\Microsoft.Web.SkipStrongNames.1.0.0\tools\SkipStrongNames.exe</SkipStrongNamesExe>
@ -64,24 +65,12 @@
</Target>
<Target Name="RestorePackages" DependsOnTargets="DownloadNuGet">
<ItemGroup>
<_NuGetPackagesAndSolutions Include="Runtime.sln" />
<!-- Avoid restoring RuntimePortable.sln directly. -->
<_NuGetPackagesAndSolutions Include="src\System.Net.Http.Formatting.NetCore\packages.config;
test\System.Net.Http.Formatting.NetCore.Test\packages.config"
Condition=" '$(BuildPortable)' == 'true' " />
<_ProjectsToRestore Include="test\System.Net.Http.Formatting.NetStandard.Test\System.Net.Http.Formatting.NetStandard.Test.csproj"
Condition=" '$(BuildPortable)' == 'true' " />
</ItemGroup>
<Message Text="Restoring NuGet packages..." Importance="High" />
<Exec Command='"$(NuGetExe)" restore "%(_NuGetPackagesAndSolutions.Identity)" ^
-PackagesDirectory packages -NonInteractive -Verbosity quiet' />
<MSBuild Projects="@(_ProjectsToRestore)" Targets="Restore"
BuildInParallel="$(BuildInParallel)"
Condition=" '$(BuildPortable)' == 'true' "
Properties="Configuration=$(Configuration);CodeAnalysis=$(CodeAnalysis);StyleCopEnabled=$(StyleCopEnabled);VisualStudioVersion=$(VisualStudioVersion)" />
<Message Text="%0ARestoring NuGet packages..." Importance="High" />
<MSBuild Projects="@(SolutionsToBuild)" Targets="Restore"
BuildInParallel="$(RestoreInParallel)"
Properties="Configuration=$(Configuration);CodeAnalysis=$(CodeAnalysis);StyleCopEnabled=$(StyleCopEnabled);
RestorePackagesConfig=true;VisualStudioVersion=$(VisualStudioVersion)" />
<Message Importance="High" Text="" />
</Target>
<!-- Pick the right Microsoft.Web.FxCop package to use and copy it to a standard location. -->
@ -96,7 +85,7 @@
Properties="Configuration=Release;OutputPath=$(CustomFxCopRulesPath)" />
</Target>
<Target Name="Build" DependsOnTargets="RestorePackages;BuildTools">
<Target Name="Build" DependsOnTargets="RestoreSkipStrongNames;RestorePackages;BuildTools">
<!-- we need to batch the solution files since they both build Microsoft.TestCommon -->
<Error Condition=" '$(CodeAnalysis)' == 'true' and '$(Configuration)' == 'Release' " Text="Unable to run code analysis in Release configuration. Release assemblies do not include SuppressMessage attributes (so code analysis would always fail with the errors that are normally suppressed)." />
<MakeDir Directories="bin\$(Configuration)" />

Просмотреть файл

@ -27,10 +27,10 @@ jobs:
pool:
${{ if eq(variables['System.TeamProject'], 'public') }}:
name: NetCore-Public
demands: ImageOverride -equals windows.vs2017.amd64.open
demands: ImageOverride -equals windows.vs2019.amd64.open
${{ else }}:
name: NetCore1ESPool-Internal
demands: ImageOverride -equals windows.vs2017.amd64
demands: ImageOverride -equals windows.vs2019.amd64
timeoutInMinutes: 30
strategy:

Просмотреть файл

@ -7,12 +7,11 @@ mkdir bin
:Build
REM Find the most recent 32bit MSBuild.exe on the system. Require v15.0 (installed with VS2017) or later since .NET
REM Core projects are coming soon.
REM Use `vswhere` for the search since %ProgramFiles(x86)%\msbuild\15.0\Bin\MSBuild.exe almost never exists.
REM Find the most recent 32bit MSBuild.exe on the system. Require v16.0 (installed with VS2019) or later.
REM Use `vswhere` for the search because it can find all VS installations.
set vswhere="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
if not exist %vswhere% (
set VsWhere="%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe"
set vswhere="%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe"
)
if not exist %vswhere% (
REM vswhere.exe not in normal locations; check the Path.
@ -25,19 +24,29 @@ if not exist %vswhere% (
goto BuildFail
)
REM We're fine w/ any .NET SDK newer than 2.1.500 but also need a 2.1.x runtime. Microsoft.Net.Core.Component.SDK.2.1
REM actually checks for only the runtime these days.
set InstallDir=
for /f "usebackq tokens=*" %%i in (`%vswhere% -version ^[15^,16^) -latest -prerelease -products * ^
-requires Microsoft.Component.MSBuild -requires Microsoft.Net.Core.Component.SDK.2.1 ^
for /f "usebackq tokens=*" %%i in (`%vswhere% -version 16 -latest -prerelease -products * ^
-requires Microsoft.Component.MSBuild ^
-requires Microsoft.NetCore.Component.SDK ^
-requires Microsoft.Net.Core.Component.SDK.2.1 ^
-property installationPath`) do (
set InstallDir=%%i
set InstallDir="%%i"
)
if exist "%InstallDir%\MSBuild\15.0\Bin\MSBuild.exe" (
set MSBuild="%InstallDir%\MSBuild\15.0\Bin\MSBuild.exe"
if exist %InstallDir%\MSBuild\Current\Bin\MSBuild.exe (
set MSBuild=%InstallDir%\MSBuild\Current\Bin\MSBuild.exe
) else (
echo Could not find MSBuild.exe. Please install the VS2017 BuildTools component or a workload that includes it.
echo Could not find MSBuild.exe. Please install the VS2019 BuildTools component or a workload that includes it.
goto BuildFail
)
REM Configure NuGet operations to work w/in this repo i.e. do not pollute system packages folder.
REM Note this causes two copies of packages restored using packages.config to land in this folder e.g.
REM StyleCpy.5.0.0/ and stylecop/5.0.0/.
set "NUGET_PACKAGES=%CD%\packages"
REM Are we running in a local dev environment (not on CI)?
if DEFINED CI (set Desktop=false) else if DEFINED TEAMCITY_VERSION (set Desktop=false) else (set Desktop=true)

Просмотреть файл

@ -1,6 +1,6 @@
{
"sdk": {
"version": "2.1.500",
"rollForward": "latestPatch"
"rollForward": "major"
}
}

Просмотреть файл

@ -6,5 +6,7 @@
<IncludeAll Action="Error" />
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
<Rule Id="CA1062" Action="None" />
<!-- Ignore int.ToString(...) calls w/o an IFormatProvider in old code. -->
<Rule Id="CA1305" Action="None" />
</Rules>
</RuleSet>

Просмотреть файл

@ -266,13 +266,14 @@
<HintPath>..\..\packages\Microsoft.Net.Http.2.2.13\lib\portable-net40+sl4+win8+wp71\System.Net.Http.Primitives.dll</HintPath>
</Reference>
</ItemGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<Import Project="..\..\packages\Microsoft.Bcl.Build.1.0.8\tools\Microsoft.Bcl.Build.targets" />
<Import Project="..\..\packages\Microsoft.Bcl.Build.1.0.8\tools\Microsoft.Bcl.Build.targets"
Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.8\tools\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\Microsoft.Bcl.Build.1.0.8\tools\Microsoft.Bcl.Build.targets')"
Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Bcl.Build.1.0.8\tools\Microsoft.Bcl.Build.targets'))" />
</Target>
</Project>

Просмотреть файл

@ -1,6 +1,6 @@
<Project>
<Import Project="..\Directory.Build.targets" />
<Import Project="..\packages\**\xunit.runner.msbuild.props" />
<Import Project="..\packages\xunit.runner.msbuild.2.3.1\**\xunit.runner.msbuild.props" />
<Target Name="Test" DependsOnTargets="_TestWithVSTest;_TestWithDotnetTest;_TestWithRunner" />

Просмотреть файл

@ -317,14 +317,21 @@
<Analyzer Include="..\..\packages\xunit.analyzers.0.7.0\analyzers\dotnet\cs\xunit.analyzers.dll" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\packages\Microsoft.Bcl.Build.1.0.8\tools\Microsoft.Bcl.Build.targets" />
<Import Project="..\..\packages\Microsoft.Bcl.Build.1.0.8\tools\Microsoft.Bcl.Build.targets"
Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.8\tools\Microsoft.Bcl.Build.targets')" />
<Import Project="..\..\packages\xunit.core.2.3.0\build\xunit.core.targets"
Condition="Exists('..\..\packages\xunit.core.2.3.0\build\xunit.core.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\xunit.core.2.3.0\build\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.core.2.3.0\build\xunit.core.props'))" />
<Error Condition="!Exists('..\..\packages\xunit.core.2.3.0\build\xunit.core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.core.2.3.0\build\xunit.core.targets'))" />
<Error Condition="!Exists('..\..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props'))" />
<Error Condition="!Exists('..\..\packages\Microsoft.Bcl.Build.1.0.8\tools\Microsoft.Bcl.Build.targets')"
Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Bcl.Build.1.0.8\tools\Microsoft.Bcl.Build.targets'))" />
<Error Condition="!Exists('..\..\packages\xunit.core.2.3.0\build\xunit.core.props')"
Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.core.2.3.0\build\xunit.core.props'))" />
<Error Condition="!Exists('..\..\packages\xunit.core.2.3.0\build\xunit.core.targets')"
Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.core.2.3.0\build\xunit.core.targets'))" />
<Error Condition="!Exists('..\..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props')"
Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props'))" />
</Target>
<Import Project="..\..\packages\xunit.core.2.3.0\build\xunit.core.targets" Condition="Exists('..\..\packages\xunit.core.2.3.0\build\xunit.core.targets')" />
</Project>

Просмотреть файл

@ -1,7 +1,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<StyleCopMsBuildRunner Include="$(WebStackRootPath)packages\**\StyleCop.dll"/>
<StyleCopAdditionalAddins Include="$(WebStackRootPath)packages\**\Microsoft.Web.StyleCop.dll" />
<StyleCopMsBuildRunner Include="$(WebStackRootPath)packages\StyleCop.5.0.0\**\StyleCop.dll"/>
<StyleCopAdditionalAddins Include="$(WebStackRootPath)packages\Microsoft.Web.SkipStrongNames.1.0.0\**\Microsoft.Web.StyleCop.dll" />
<StyleCopAdditionalAddinPaths Include="@(StyleCopAdditionalAddins -> '%(RootDir)%(Directory)')" />
</ItemGroup>

Просмотреть файл

@ -10,7 +10,8 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.Web.FxCop</RootNamespace>
<AssemblyName>Microsoft.Web.FxCop</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<!-- May need to be updated as FxCopSdk.dll is migrated to newer TFMs. -->
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<OutputPath Condition=" '$(OutputPath)' == '' ">bin\$(Configuration)</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">