Azure Devops - how to precompile Asp.Net Framework MVC website

Viewed 352

I have inherited a couple of Asp.Net 4.8 MVC websites that I am building and deploying using Azure Devops Pipelines. Each page is very slow to start up the first time each one is hit, so I want to precompile them.

Following the advice in this SO question:

Azure devops pipeline - Visual studio build step - How to precompile cshtml views?

I add /p:PrecompileBeforePublish=true" to the MsBuild parameters.

However, like one of the comments on there, that gives me the following build error:

[error]Project\obj\release\aspnetcompilemerge\source\web.config(52,0): Error ASPCONFIG: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.

A reply suggested adding the following to the MsBuild parameters:

/p:BaseIntermediateOutputPath=$(build.artifactstagingdirectory)\tmp_obj\

This, however, then gave me hundreds of errors along the lines of:

Error CS0234: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)

Which has rather left me flummoxed.

Both sites compile and run fine in VS2019, however I can recreate the issue locally by running MsBuild using Powershell:

Invoke-MsBuild -Path "solution.sln" -MsBuildParameters "/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:AutoParameterizationWebConfigConnectionStrings=False /p:PackageLocation=\Users\name\code\repofolder\packages\\ /p:PrecompileBeforePublish=true /p:BaseIntermediateOutputPath=\tmp_obj\\"

Any suggestions as to what I'm doing wrong here?

0 Answers
Related