Question: How do you resolve Visual Studio Error When Publishing: Microsoft.WebTools.Shared.Exceptions.WebToolsException: Build failed. Check the Output window for more details.
- System.AggregateException: One or more errors occurred. ---> Microsoft.WebTools.Shared.Exceptions.WebToolsException: Build failed. Check the Output window for more details.
--- End of inner exception stack trace ---
Solution: This error happens when there have been current updates to Visual Studio 2019 at least to my knowledge. When I experienced this error, I had other applications in the Solution, it looks like Visual Studio experiences problems building those other projects included in the same Solution.
If you need to read more about your specific project scenario, check the output window in Visual Studio for error details.
Keep in mind that the way you find out about the Error itself is by navigating to the Error List in the Output Window of Visual Studio. If you are using VS Code, find out where you see the logs for the Builds. See the image below if you are using Visual Studio.
If you find out that the error says "Found multiple output files with the same relative paths" then just add the line of code below to the PublishProfile.puxml
Otherwise, this is helpful in diagnosing the issue, for example, the error logged into the OutPut Console (Build + IntelliSense) might say " The RuntimeIdentifier platform 'win-x64' and the PlatformTarget 'X86' must be compatible" then you will know that you need to have the same platform in both the PlatformTarget and Publish profile.
If the above did not help you, then try the following to resolve this error, follow the steps below:
1. Stop or Cancel Building the application if the build is stuck.
2. Make sure you save your changes
3. Close Visual Studio and open your project again.
4. When the project loads into Visual Studio 2019, Clean the Solution
4. Then build the solution
5. After building the solution, go ahead and publish if you need to.
Check to see if you have multiple appsettings.json in Class Library. This is common when you have a DataLayer Class Library that has ORM or Data Access Layer, avoid including app settings in Class Library unless if you really need it.