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

标签 asp.net azure-devops aspnet-compiler

我有一个使用 ASP.NET 网站(不是 ASP.NET Web 应用程序)的旧代码库,并且正在尝试在 Azure 上为其构建管道开发运营。

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

构建步骤的完整日志位于我的帖子底部,但这是我特别陷入困境的地方:

Project "D:\a\9\s\Hello.sln" (1) is building "D:\a\9\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\9\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\9\s\WebSite1_1_.metaproj]

我应该注意到,这似乎与 Microsoft.CodeDom.Providers.DotNetCompilerPlatform 程序集无关。在我实际的 ASP.NET 网站(不是我正在使用的这个小测试网站)中,如果网站的web.config 包含此内容,例如:

    <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.Infrastruct 的错误。显然,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://learn.microsoft.com/azure/devops/pipelines/tasks/build/visual-studio-build
==============================================================================
##[command]"D:\a\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.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\1.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\1.166.2\ps_modules\MSBuildHelpers\vswhere.exe" -version [15.0,16.0) -latest -format json
##[command]"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe" "D:\a\9\s\Hello.sln" /nologo /nr:false /dl:CentralLogger,"D:\a\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.166.2\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll";"RootDetailId=f1e19740-d1c0-4435-a66d-d2b7ccec211f|SolutionDir=D:\a\9\s"*ForwardingLogger,"D:\a\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.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\9\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\9\s\Hello.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
  Building solution configuration "release|any cpu".
Project "D:\a\9\s\Hello.sln" (1) is building "D:\a\9\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\9\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\9\s\WebSite1_1_.metaproj]
Done Building Project "D:\a\9\s\WebSite1_1_.metaproj" (default targets) -- FAILED.
Done Building Project "D:\a\9\s\Hello.sln" (default targets) -- FAILED.

Build FAILED.

"D:\a\9\s\Hello.sln" (default target) (1) ->
"D:\a\9\s\WebSite1_1_.metaproj" (default target) (2) ->
(Build target) -> 
  D:\a\9\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\9\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 Pipeline 中工作,但它们可以工作。这是我着陆的地方...

  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
  • 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)'
    
  • 在运行 aspnet_compiler.exe 之前,NuGet 不会运行安装 PowerShell 脚本将所有 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'
    

    关于asp.net - Azure DevOps Pipelines 可以构建 ASP.NET 网站吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63639769/

    相关文章:

    asp.net - 在类库中添加 System.Web.Script 引用

    .net - 5秒查看部署状态

    asp.net - 为什么 ASP.NET 控件上的事件处理程序属性的属性有前缀(加载事件处理程序的 OnLoad)

    c# - 在命令行使用 aspnet_compiler 抑制编译器警告

    c# - 尝试在 api 启动后运行方法

    c# - IIS7 session 失去其值(value)

    docker - 通过 azure 管道部署时,如何解决 docker-compose 文件中卷装载问题的变量替换?

    visual-studio-2015 - Azure DevOps Build - 发布时不会在 bin 文件夹中创建 .compiled 文件

    .net - ASPNET编译器错误ASPCONFIG : Could not load file or assembly 'Microsoft.VisualBasic.Activities.Compiler' or one of its dependencies

    c# - Asp.net mvc 5 在添加内容时添加时间戳?