Azure DevOps Pipelines 可以构建 ASP.NET 网站吗?

Can Azure DevOps Pipelines build an ASP.NET Web Site?

我有一个使用 ASP.NET 网站的旧代码库(不是 ASP.NET 网络应用程序 ) 并尝试在 Azure DevOps 上为其构建管道。

在 运行 过程到达 aspnet_compiler.exe 遇到一些困难后,我创建了一个简单的测试解决方案,其中包含一个 ASP.NET Web 表单站点,该站点是从 VS2019 中的模板生成的。然后,我使用 ASP.NET 模板和 运行 创建了一个管道,但以熟悉的失败告终。测试解决方案和实际解决方案在同一个地方失败,所以至少我已经查明了问题......不幸的是,我不知道如何解决它。

构建步骤的完整日志在我的 post 的底部,但这是我特别卡住的地方:

Project "D:\a\s\Hello.sln" (1) is building "D:\a\s\WebSite1_1_.metaproj" (2) on node 1 (default targets).
Build:
  C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v /localhost_51752 -p WebSite1\ -u -f PrecompiledWeb\localhost_51752\ 
##[error]WebSite1\web.config(116,0): Error ASPCONFIG: The CodeDom provider type "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" could not be located.
D:\a\s\WebSite1\web.config(116): error ASPCONFIG: The CodeDom provider type "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" could not be located. [D:\a\s\WebSite1_1_.metaproj]

我应该注意到,这似乎与 Microsoft.CodeDom.Providers.DotNetCompilerPlatform 程序集无关。在我实际的 ASP.NET 网站(不是我正在使用的这个小测试网站)中,如果网站的 web.config 包含此相同的“Error ASPCONFIG: ... * could not be located.”错误,例如:

    <compilation debug="true" defaultLanguage="c#" targetFramework="4.8">
      <assemblies>
        <add assembly="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>

在那种情况下,它会抛出相同的错误,但大约是 Microsoft.Web.Infrastructure。显然,aspnet_compiler.exe 无法找到我的引用,但我不知道缺少什么——引用是否没有被复制到某个地方,或者进程是否没有在正确的位置寻找它们,或者...?

这是整个 Azure DevOps Pipeline 构建日志:

##[section]Starting: Build solution
==============================================================================
Task         : Visual Studio build
Description  : Build with MSBuild and set the Visual Studio version property
Version      : 1.166.2
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/visual-studio-build
==============================================================================
##[command]"D:\a\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda.166.2\ps_modules\MSBuildHelpers\vswhere.exe" -version [16.0,17.0) -latest -format json
##[command]"D:\a\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda.166.2\ps_modules\MSBuildHelpers\vswhere.exe" -version [16.0,17.0) -products Microsoft.VisualStudio.Product.BuildTools -latest -format json
##[command]"D:\a\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda.166.2\ps_modules\MSBuildHelpers\vswhere.exe" -version [15.0,16.0) -latest -format json
##[command]"C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\MSBuild.0\Bin\msbuild.exe" "D:\a\s\Hello.sln" /nologo /nr:false /dl:CentralLogger,"D:\a\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda.166.2\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll";"RootDetailId=f1e19740-d1c0-4435-a66d-d2b7ccec211f|SolutionDir=D:\a\s"*ForwardingLogger,"D:\a\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda.166.2\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="D:\a\a\" /p:platform="any cpu" /p:configuration="release" /p:VisualStudioVersion="15.0" /p:_MSDeployUserAgent="VSTS_ab00089e-3c64-4607-ad03-57473b1db76f_build_3_0"
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Build started 8/28/2020 6:48:44 PM.
Project "D:\a\s\Hello.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
  Building solution configuration "release|any cpu".
Project "D:\a\s\Hello.sln" (1) is building "D:\a\s\WebSite1_1_.metaproj" (2) on node 1 (default targets).
Build:
  C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v /localhost_51752 -p WebSite1\ -u -f PrecompiledWeb\localhost_51752\ 
##[error]WebSite1\web.config(116,0): Error ASPCONFIG: The CodeDom provider type "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" could not be located.
D:\a\s\WebSite1\web.config(116): error ASPCONFIG: The CodeDom provider type "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" could not be located. [D:\a\s\WebSite1_1_.metaproj]
Done Building Project "D:\a\s\WebSite1_1_.metaproj" (default targets) -- FAILED.
Done Building Project "D:\a\s\Hello.sln" (default targets) -- FAILED.

Build FAILED.

"D:\a\s\Hello.sln" (default target) (1) ->
"D:\a\s\WebSite1_1_.metaproj" (default target) (2) ->
(Build target) -> 
  D:\a\s\WebSite1\web.config(116): error ASPCONFIG: The CodeDom provider type "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" could not be located. [D:\a\s\WebSite1_1_.metaproj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:09.47
##[error]Process 'msbuild.exe' exited with code '1'.
##[section]Finishing: Build solution

网站似乎需要一点额外的爱才能在 Azure DevOps 管道中工作,但它们可以工作。这是我着陆的地方...

  1. 管道环境没有安装 Visual Studio。确保您的 *.refresh 文件指向下载的包(即 NuGet 自动放入您的包目录的东西),而不是 Visual Studio 共享包目录。

在一个新的网站项目中,例如Bin\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll.refresh的内容默认为:

..\..\..\Program Files (x86)\Microsoft Visual Studio\Shared\Packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll

...但应该是:

..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll
  1. NuGet 不知道它需要为网站恢复包,因为没有 *.csproj 告诉它。添加自定义 NuGet 还原任务(其中“WebSite1”是您网站所在的目录):
steps:
- task: NuGetCommand@2
  displayName: 'NuGet Restore for Web Site'
  inputs:
    command: custom
    arguments: 'restore $(Build.SourcesDirectory)\WebSite1\packages.config -SolutionDirectory $(Build.SourcesDirectory)'
  1. NuGet 不会 运行 安装 PowerShell 脚本以在 运行 宁 aspnet_compiler.exe 之前将所有 Roslyn 文件放入您的 Bin 目录中。您必须通过复制文件任务自己完成此操作:
steps:
- task: CopyFiles@2
  displayName: 'Copy Roslyn files'
  inputs:
    SourceFolder: '$(Build.SourcesDirectory)\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\tools\RoslynLatest'
    TargetFolder: '$(Build.SourcesDirectory)\WebSite1\Bin\roslyn'