Fix “Invalid input 'WebApplication.csproj'. The file type was not recognized.” Error in Azure DevOps, ASP.Net Core Build Definition
On Visual Studio Team Services, to quickly and easily build your ASP.Net Core applications, you can use the pre-built ASP.Net Core Template in the Build section of VSTS.
But when you try to use this ASP.Net Core Pre-Built template with a .csproj based .Net Core Application, you run in to an issue where the build will fail at restoring the NuGet dependencies with the error message,
Invalid input 'xxxxxxxxxx.csproj'. The file type was not recognized.
This is because of the build agent that is selected by default for this template. The Hosted Agent is selected by default and this Hosted Agent only support project.json based Asp.Net Core Applications. It cannot compile .csproj based ASP.Net Core applications.
There is a simple solution for this issue, that is to change the build agent to Hosted VS2017 Agent which supports building .csproj based ASP.Net Core applications. To do this, in the Edit view of the build definition go to Options tab and in the Agents section, Select Hosted VS2017 Agent from the Default Agent Queue drop down.
You can also select the Agent from the Queue Build dialog where you can select the Agent used to build the project.
But you would want to select the Agent from the Options tab and save it to the build definition, especially if you are using this definition for Continuous Integration scenario where the build gets automatically triggered and you don’t get the chance to select the Agent.
With this change your build will successfully restore the NuGet packages and will complete the build without any issues.