azure-devopsvisual-studio-2019

unable to build a asp.net app in azure devops


Able to build the app locally, but when am trying to build in azure devops pipeline.It showing below errors

I have installed EntityFramework and added system.data.entity.design assembly in webconfig file.No luck

Please find pipeline here

NuGet Restore task

webapp\CaseDatabase.DataAccess\CaseAssignmentModule\CaseQueueDbAdapter.cs(10,19): Error CS0234: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
webapp\CaseDatabase.DataAccess\CaseAssignmentModule\HoursEstDbAdapter.cs(4,19): Error CS0234: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
webapp\CaseDatabase.DataAccess\CasesModule\CaseWorkflowDbAdapter.cs(2,17): Error CS0234: The type or namespace name 'EntityFrameworkCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
webapp\CaseDatabase.DataAccess\ClientsAndContactsModule\ContactDefaultsDbAdapter.cs(5,17): Error CS0234: The type or namespace name 'EntityFrameworkCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
webapp\CaseDatabase.DataAccess\ClientsAndContactsModule\InstructionLibraryDbAdapter.cs(4,17): Error CS0234: The type or namespace name 'EntityFrameworkCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
webapp\CaseDatabase.DataAccess\DBEntityCoreModel\CaseDatabaseContext.cs(2,17): Error CS0234: The type or namespace name 'EntityFrameworkCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
webapp\CaseDatabase.DataAccess\DBEntityCoreModel\ICaseDatabaseContext.cs(2,17): Error CS0234: The type or namespace name 'EntityFrameworkCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
webapp\CaseDatabase.DataAccess\DBEntityCoreModel\ICaseDatabaseContext.cs(3,17): Error CS0234: The type or namespace name 'EntityFrameworkCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
webapp\CaseDatabase.DataAccess\DBEntityCoreModel\ICaseDatabaseContext.cs(4,17): Error CS0234: The type or namespace name 'EntityFrameworkCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
webapp\CaseDatabase.DataAccess\EntityRepository.cs(4,17): Error CS0234: The type or namespace name 'EntityFrameworkCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

Solution

  • According to the build log which shared from @Stella, this error message should caused by the package restored path.

    Firstly, it's all succeed to restore the relevant package with the Nuget restore task. And also, the packages needed all has been restored. It's restored folder location is D:\a\1\s\webapp\Websites\packages which same with location defined in Nuget.config ..\packages

    In the Visual Studio Build log, there has the following message:

    Considered "..\ThirdParty\NuGetPackages\EntityFramework.6.1.2\lib\net45\EntityFramework.dll", but it didn't exist.
    ***
    ***
    Considered "..\ThirdParty\NuGetPackages\EntityFramework.6.1.2\lib\net45\EntityFramework.SqlServer.dll", but it didn't exist.
    ***
    ***
    ***
    

    According to these message which displayed in Visual Studio Build task, you can see it is finding the package location under the folder path ..\ThirdParty\NuGetPackages. As normal, this path is controlled by the <HintPath>... </HintPath>.

    Now, it would be very easy to know the error caused: the package location which found during the build does not match with its actually package restored location in Nuget restore task.

    As normal, its default location should be ..\packages\..., which same with default location defined in Nuget.config. I assume its local repos path should ever be changed, then its HintPath which defined in csproj file are also be changed automatically. But, in Nuget.config, its package default location are still keep default. That will cause when package restore, it follow the location defined in Nuget.config. But during build time, since it look for the package with the csproj ... defined, build can not know the actually package restored location. Then caused these error message.


    To solve this issue, there has 2 solutions.

    Run the below command to reinstall all of packages, thus the HintPath can all changed into default location ..\packages\..., which can sync with defined in Nuget.config.

    Update-Package -reinstall
    

    This logic of this solution is revoke HintPath as default location, thus it can keep sync with definition in Nuget.config.

    After execute the command, the HintPath should same look as this:

    enter image description here

    The logic of second solution is modify the package location definition in Nuget.config file. Make it sync with HintPath, at this time, the location of the package restored will be the same as the location of the package at build time.

    Add the following script into Nuget.config file:

    <configuration>
      <config>
        <add key="repositoryPath" value="xxxx" />
      </config>
      ... 
    </configuration>
    

    Just try with one solution, then build in Visual Studio locally. After it is succeed, then push it into Azure Devops, build with the same task configuration previously, use nuget, nuget restore, VS build, publish artifacts.

    Hope this helps.