user11708158
user11708158

Reputation:

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?)

Upvotes: 2

Views: 1845

Answers (2)

Hopper
Hopper

Reputation: 453

I just experienced this same issue, though I fixed it in a different way than the other, accepted answer: the Project getting the CS0234 error's Entity Framework package was 6.4.0. Looking at the Package Dependencies, it clearly states ".NETStandard,Version=2.1" and, as it turns out, the Project was .NET 2.0. Downgrading the Version to 6.2.0 was all it took for the DevOps Pipeline to finally succeed.

This seems like such an obvious resolution but this legacy solution had well over 100 Warnings and, because it Built/Ran locally, it confounded the entire team for hours. I hope this helps save others some time!

Upvotes: 0

Mengdi Liang
Mengdi Liang

Reputation: 18958

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.

  • Reinstall packages in Visual Studio

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

  • Modify the Nuget.config file

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.

Upvotes: 1

Related Questions