0

I'm trying to publish a website in Visual Studio 2019. Publishing to a folder is successful with default settings but when I check Precompile during publishing option, I get following error while publishing the website.

C:\<User Dir>\AppData\Local\Temp\WebSitePublish\MyWebSite--144316003\obj\Debug\AspnetCompileMerge\Source\bin\release\publish\web.config(167,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.

I tried following solutions which I found on similar questions:

  • Clear solution and Build solution
  • Rebuild Solution
  • Delete obj/Debug and obj/Release folder
  • Delete publish profile and create new one
  • Following the same steps again after opening Visual Studio in Admin mode

Also, this so post suggested that the problem might be with Microsoft.Net.Compilers. But when I search for this installed nuget package, I can't find it. Can someone please suggest on this what's causing this issue and how can it be resolved?

Update: Upon trying different Publish settings, I came to know this error occurs only when Precompile during publishing option is checked.

Akanksha_p
  • 916
  • 12
  • 20
  • Hi Akanksha_p, glad to know you've found the solution to resolve this issue! Please consider accepting it as an answer to change its status to Answered. It will also help others to solve a similar issue. See [can I answer my own question..](https://stackoverflow.com/help/self-answer), Just a reminder :) – Jiale Xue - MSFT Jan 03 '22 at 02:43

1 Answers1

0

I was able to publish the same website in target folder by cloning it again at a new location.

I built the newly cloned project in release mode and published it with Precompile during publishing enabled and it did not throw any error.

Peter Csala
  • 17,736
  • 16
  • 35
  • 75
Akanksha_p
  • 916
  • 12
  • 20