asp.netazure-devopsaspnet-compiler

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


I have an older codebase that uses an ASP.NET Web Site (not an ASP.NET Web App) and am trying to construct a Pipeline for it on Azure DevOps.

After running into some difficulty when the process reaches aspnet_compiler.exe, I created a simple test solution containing a single ASP.NET Web Forms Site, generated from the template in VS2019. I then created a Pipeline using the ASP.NET template and ran it, which ended in familiar failure. The test solution and the real solution are failing at the same spot, so at least I have pinpointed the problem... unfortunately, I don't know how to address it.

The full log for the build step is at the bottom of my post, but here's where I'm stuck specifically:

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]

I should note that this doesn't appear to be related to the Microsoft.CodeDom.Providers.DotNetCompilerPlatform assembly specifically. In my actual ASP.NET Web Site (not this little test one I'm working with here), this same "Error ASPCONFIG: ... * could not be located." error occurs if the site's web.config contains this, for example:

    <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>

In that case, it will throw the same error, but about Microsoft.Web.Infrastructure instead. Clearly, aspnet_compiler.exe is unable to find my references, but I don't know what's missing -- are the references not being copied somewhere, or is the process not looking for them in the right place, or... ?

Here is the entire Azure DevOps Pipeline build log:

##[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

Solution

  • Web Sites seem to need a little extra love to work in an Azure DevOps Pipeline, but they can work. Here's where I landed...

    1. The Pipeline environment doesn't have Visual Studio installed. Make certain that your *.refresh files are pointing to downloaded packages (i.e. stuff NuGet automatically puts in your packages directory), not to the Visual Studio shared packages directory.

    In a new Web Site project, for example, the content of Bin\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll.refresh defaults to:

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

    ...but should be:

    ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll
    
    1. NuGet has no idea it needs to restore packages for a Web Site because there's no *.csproj to tell it so. Add a custom NuGet restore task (where "WebSite1" is the directory your Web Site is in):
    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 won't run the install PowerShell script to put all the Roslyn files in your Bin directory prior to running aspnet_compiler.exe. You have to do that yourself with a Copy files task:
    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'