dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.68k stars 3.16k forks source link

Use Nuget.Config file in migrations bundle command #33921

Open VincentOspazi opened 3 months ago

VincentOspazi commented 3 months ago

Dear,

I'm trying to use the "dotnet.exe ef migrations bundle" command with a nuget.config file defined on the sln folder level, but I don't see any parameters where I can define the path or the service connection name to use to authenticate against the external feed defined in the nuget.config. I'm trying this in azure pipelines, and external feed is in Nexus.

Steps in the pipeline:

- task: DotNetCoreCLI@2
          inputs:
            command: 'custom'
            custom: 'ef'
            arguments: 'migrations bundle --configuration bundle -s "$(System.DefaultWorkingDirectory)/repo/${{parameters.workingDirectory}}/${{parameters.migrationsProject}}" -f --output "$(Build.ArtifactStagingDirectory)/migrations/efbundle_main.exe" --verbose'

the error:

starts when ef is building the bundle:

Building bundle...
dotnet publish --runtime win10-x64 --output C:\Users\SRVTFSBUILD2019prd\AppData\Local\Temp\asrz5ytu.zcf\publish --no-self-contained
  Determining projects to restore...
  Restored D:\AzDO_Services_R-xxxxxxxx\agent1\_work\1056\s\repo\src\api\xxxxxx.AutomaticUpload.Models\xxxxxxxxxxx.csproj (in 540 ms).
  Restored D:\AzDO_Services_R-xxxxxxxx\agent1\_work\1056\s\repo\src\api\xxxxxx.AutomaticUpload.Components\xxxxxxxxxxxx.csproj (in 275 ms).
C:\Users\SRVTFSBUILD2019prd\AppData\Local\Temp\asrz5ytu.zcf\efbundle_main.csproj : error NU1101: Unable to find package <custom package stored in nexus>. No packages exist with this id in source(s): nuget.org
C:\Users\SRVTFSBUILD2019prd\AppData\Local\Temp\asrz5ytu.zcf\efbundle_main.csproj : error NU1101: Unable to find package <custom package stored in nexus>. No packages exist with this id in source(s): nuget.org
C:\Users\SRVTFSBUILD2019prd\AppData\Local\Temp\asrz5ytu.zcf\efbundle_main.csproj : error NU1101: Unable to find package <custom package stored in nexus>. No packages exist with this id in source(s): nuget.org
C:\Users\SRVTFSBUILD2019prd\AppData\Local\Temp\asrz5ytu.zcf\efbundle_main.csproj : error NU1101: Unable to find package <custom package stored in nexus>. No packages exist with this id in source(s): nuget.org
C:\Users\SRVTFSBUILD2019prd\AppData\Local\Temp\asrz5ytu.zcf\efbundle_main.csproj : error NU1101: Unable to find package <custom package stored in nexus>. No packages exist with this id in source(s): nuget.org
C:\Users\SRVTFSBUILD2019prd\AppData\Local\Temp\asrz5ytu.zcf\efbundle_main.csproj : error NU1101: Unable to find package <custom package stored in nexus>. No packages exist with this id in source(s): nuget.org
C:\Users\SRVTFSBUILD2019prd\AppData\Local\Temp\asrz5ytu.zcf\efbundle_main.csproj : error NU1101: Unable to find package <custom package stored in nexus>. No packages exist with this id in source(s): nuget.org
C:\Users\SRVTFSBUILD2019prd\AppData\Local\Temp\asrz5ytu.zcf\efbundle_main.csproj : error NU1101: Unable to find package Pacaya.Business. No packages exist with this id in source(s): nuget.org
  Failed to restore C:\Users\SRVTFSBUILD2019prd\AppData\Local\Temp\asrz5ytu.zcf\efbundle_main.csproj (in 5,53 sec).
  Restored D:\AzDO_Services_R-xxxxxxxxx\agent1\_work\1056\s\repo\src\api\Cxxxxxs\Cxxxxxxxxxxxxxx.csproj (in 16,88 sec).
  Restored D:\AzDO_Services_R-xxxxxxxxx\agent1\_work\1056\s\repo\src\api\Cxxxxxs\xxxxxxxxxxxxxxxi.csproj (in 16,88 sec).
Microsoft.EntityFrameworkCore.Tools.CommandException: Build failed. Use --verbose to see errors.

I would expect it to try and get those custom packages out of the nexus feed as that is defined in the nuget.config.

The dotnet restore and dotnet build tasks are running ok, but with the restore task I can give along the nuget.config path and the service connection it needs to use.

tried it also with --no-build but then the configuration bundle seems to try and get the packages in the debug configuration folder, while the dotnet build of the sln is in the release configuration.

Include provider and version information

EF Core version: 7.* Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: NET 7.x Operating system: Windows Server 2022 IDE: on build server with Azure devops Build Agent

ajcvickers commented 3 months ago

@VincentOspazi This looks like a duplicate of #27456. Can you confirm that issue covers what you are trying to do?

VincentOspazi commented 3 months ago

@ajcvickers: Thanks for relating to the issue number, I'v found that also but the workaround proposed does not work in my case.

Don't know why it is not picking up the nuget.config file. Is it maybe because the nuget.config file is located at the .sln level folder that is about 3 folders higher in the folderstructure then where the csproj of the migrations is situated?

EDIT:

even a copy of the nuget.config to the folder of the target project does not solve the problem.

Is there any other way I can solve this?

thanks

ajcvickers commented 3 months ago

@VincentOspazi Can you post the output when you do this, "even a copy of the nuget.config to the folder of the target project does not solve the problem?"

VincentOspazi commented 3 months ago

Hi @ajcvickers,

hereby the logs

image

024-06-10T09:54:13.2885806Z     33 Warning(s)
2024-06-10T09:54:13.2886239Z     0 Error(s)
2024-06-10T09:54:13.2886558Z 
2024-06-10T09:54:13.2887041Z Time Elapsed 00:01:19.46
2024-06-10T09:54:13.3390627Z Build succeeded.
2024-06-10T09:54:13.3552557Z dotnet exec --depsfile D:\AzDO_Services_xxxxxxxxxx\agent1\_work\1056\s\repo\src\api\xxxxxxxxxx.AutomaticUpload.Migrations\bin\bundle\net7.0\xxxxxxxxxx.AutomaticUpload.Migrations.deps.json --additionalprobingpath D:\AzDO_Services_xxxxxxxxxx\agent1\_work\1056\s\repo\src\api\packages --runtimeconfig D:\AzDO_Services_xxxxxxxxxx\agent1\_work\1056\s\repo\src\api\xxxxxxxxxx.AutomaticUpload.Migrations\bin\bundle\net7.0\xxxxxxxxxx.AutomaticUpload.Migrations.runtimeconfig.json C:\Users\SRVTFSBUILD2019prd\.dotnet\tools\.store\dotnet-ef\7.0.20\dotnet-ef\7.0.20\tools\net6.0\any\tools\netcoreapp2.0\any\ef.dll migrations bundle -f --output D:\AzDO_Services_xxxxxxxxxx\agent1\_work\1056\a/migrations/efbundle_main.exe --assembly D:\AzDO_Services_xxxxxxxxxx\agent1\_work\1056\s\repo\src\api\xxxxxxxxxx.AutomaticUpload.Migrations\bin\bundle\net7.0\xxxxxxxxxx.AutomaticUpload.Migrations.dll --project D:\AzDO_Services_xxxxxxxxxx\agent1\_work\1056\s\repo\src\api\xxxxxxxxxx.AutomaticUpload.Migrations\xxxxxxxxxx.AutomaticUpload.Migrations.csproj --startup-assembly D:\AzDO_Services_xxxxxxxxxx\agent1\_work\1056\s\repo\src\api\xxxxxxxxxx.AutomaticUpload.Migrations\bin\bundle\net7.0\xxxxxxxxxx.AutomaticUpload.Migrations.dll --startup-project D:\AzDO_Services_xxxxxxxxxx\agent1\_work\1056\s\repo\src\api\xxxxxxxxxx.AutomaticUpload.Migrations\xxxxxxxxxx.AutomaticUpload.Migrations.csproj --project-dir D:\AzDO_Services_xxxxxxxxxx\agent1\_work\1056\s\repo\src\api\xxxxxxxxxx.AutomaticUpload.Migrations\ --root-namespace xxxxxxxxxx.AutomaticUpload.Migrations --language C# --framework net7.0 --configuration bundle --working-dir D:\AzDO_Services_xxxxxxxxxx\agent1\_work\1056\s --verbose
2024-06-10T09:54:14.1619406Z Using assembly 'xxxxxxxxxx.AutomaticUpload.Migrations'.
2024-06-10T09:54:14.1621651Z Using startup assembly 'xxxxxxxxxx.AutomaticUpload.Migrations'.
2024-06-10T09:54:14.1623373Z Using application base 'D:\AzDO_Services_xxxxxxxxxx\agent1\_work\1056\s\repo\src\api\xxxxxxxxxx.AutomaticUpload.Migrations\bin\bundle\net7.0'.
2024-06-10T09:54:14.1623815Z Using working directory 'D:\AzDO_Services_xxxxxxxxxx\agent1\_work\1056\s\repo\src\api\xxxxxxxxxx.AutomaticUpload.Migrations'.
2024-06-10T09:54:14.1625301Z Using root namespace 'xxxxxxxxxx.AutomaticUpload.Migrations'.
2024-06-10T09:54:14.1627843Z Using project directory 'D:\AzDO_Services_xxxxxxxxxx\agent1\_work\1056\s\repo\src\api\xxxxxxxxxx.AutomaticUpload.Migrations\'.
2024-06-10T09:54:14.1636686Z Remaining arguments: .
2024-06-10T09:54:14.6791669Z Finding DbContext classes...
2024-06-10T09:54:14.6793553Z Finding IDesignTimeDbContextFactory implementations...
2024-06-10T09:54:14.6991145Z Found IDesignTimeDbContextFactory implementation 'UploadDbContextDesignTimeFactory'.
2024-06-10T09:54:14.6996156Z Found DbContext 'MigrationDbContext'.
2024-06-10T09:54:14.7000833Z Finding application service provider in assembly 'xxxxxxxxxx.AutomaticUpload.Migrations'...
2024-06-10T09:54:14.7008621Z Finding Microsoft.Extensions.Hosting service provider...
2024-06-10T09:54:14.7029370Z No static method 'CreateHostBuilder(string[])' was found on class 'Program'.
2024-06-10T09:54:14.7269793Z No application service provider was found.
2024-06-10T09:54:14.7507259Z Finding DbContext classes in the project...
2024-06-10T09:54:14.7750091Z Using DbContext factory 'UploadDbContextDesignTimeFactory'.
2024-06-10T09:54:21.7324804Z Using context 'MigrationDbContext'.
2024-06-10T09:54:21.7410069Z Creating DbConnection.
2024-06-10T09:54:21.7816491Z 'MigrationDbContext' disposed.
2024-06-10T09:54:21.7937039Z Building bundle...
2024-06-10T09:54:21.8200984Z dotnet publish --runtime win10-x64 --output C:\Users\SRVTFSBUILD2019prd\AppData\Local\Temp\jqerrlg2.liy\publish --no-self-contained
2024-06-10T09:54:22.7436452Z   Determining projects to restore...
2024-06-10T09:54:24.0625637Z   Restored D:\AzDO_Services_xxxxxxxxxx\agent1\_work\1056\s\repo\src\api\xxxxxxxxxx.AutomaticUpload.Components\xxxxxxxxxx.AutomaticUpload.Components.csproj (in 573 ms).
2024-06-10T09:54:24.1348815Z   Restored D:\AzDO_Services_xxxxxxxxxx\agent1\_work\1056\s\repo\src\api\xxxxxxxxxx.AutomaticUpload.Models\xxxxxxxxxx.AutomaticUpload.Models.csproj (in 573 ms).
2024-06-10T09:54:30.4081300Z C:\Users\SRVTFSBUILD2019prd\AppData\Local\Temp\jqerrlg2.liy\efbundle_main.csproj : error NU1101: Unable to find package xxxxxxxxxx.Bff.EntityFrameworkCore. No packages exist with this id in source(s): nuget.org
2024-06-10T09:54:30.4082698Z C:\Users\SRVTFSBUILD2019prd\AppData\Local\Temp\jqerrlg2.liy\efbundle_main.csproj : error NU1101: Unable to find package xxxxxxxxxx.ActivityTracking.EntityFrameworkCore. No packages exist with this id in source(s): nuget.org
2024-06-10T09:54:30.4084671Z C:\Users\SRVTFSBUILD2019prd\AppData\Local\Temp\jqerrlg2.liy\efbundle_main.csproj : error NU1101: Unable to find package xxxxxxxxxx.Api. No packages exist with this id in source(s): nuget.org
2024-06-10T09:54:30.4096540Z C:\Users\SRVTFSBUILD2019prd\AppData\Local\Temp\jqerrlg2.liy\efbundle_main.csproj : error NU1101: Unable to find package xxxxxxxxxx.Business.EntityFrameworkCore. No packages exist with this id in source(s): nuget.org
2024-06-10T09:54:30.4101331Z C:\Users\SRVTFSBUILD2019prd\AppData\Local\Temp\jqerrlg2.liy\efbundle_main.csproj : error NU1101: Unable to find package xxxxxxxxxx.Caching. No packages exist with this id in source(s): nuget.org
2024-06-10T09:54:30.4102420Z C:\Users\SRVTFSBUILD2019prd\AppData\Local\Temp\jqerrlg2.liy\efbundle_main.csproj : error NU1101: Unable to find package xxxxxxxxxx.Caching.InMemory. No packages exist with this id in source(s): nuget.org
2024-06-10T09:54:30.4102938Z C:\Users\SRVTFSBUILD2019prd\AppData\Local\Temp\jqerrlg2.liy\efbundle_main.csproj : error NU1101: Unable to find package xxxxxxxxxx.Rest. No packages exist with this id in source(s): nuget.org
2024-06-10T09:54:30.4103652Z C:\Users\SRVTFSBUILD2019prd\AppData\Local\Temp\jqerrlg2.liy\efbundle_main.csproj : error NU1101: Unable to find package xxxxxxxxxx.Business. No packages exist with this id in source(s): nuget.org
2024-06-10T09:54:32.5587481Z   Failed to restore C:\Users\SRVTFSBUILD2019prd\AppData\Local\Temp\jqerrlg2.liy\efbundle_main.csproj (in 9,06 sec).
2024-06-10T09:54:41.5127592Z   Restored D:\AzDO_Services_xxxxxxxxxx\agent1\_work\1056\s\repo\src\api\xxxxxxxxxx.AutomaticUpload.Api\xxxxxxxxxx.AutomaticUpload.Api.csproj (in 17,43 sec).
2024-06-10T09:54:41.6596014Z   Restored D:\AzDO_Services_xxxxxxxxxx\agent1\_work\1056\s\repo\src\api\xxxxxxxxxx.AutomaticUpload.Migrations\xxxxxxxxxx.AutomaticUpload.Migrations.csproj (in 18,18 sec).
2024-06-10T09:54:41.8041762Z Microsoft.EntityFrameworkCore.Tools.CommandException: Build failed. Use --verbose to see errors.
2024-06-10T09:54:41.8042298Z    at Microsoft.EntityFrameworkCore.Tools.Commands.MigrationsBundleCommand.Execute(String[] args)
2024-06-10T09:54:41.8042633Z    at Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase.<>c__DisplayClass0_0.<Configure>b__0(String[] args)
2024-06-10T09:54:41.8043048Z    at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)
2024-06-10T09:54:41.8043400Z    at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
2024-06-10T09:54:41.8043692Z Build failed. Use --verbose to see errors.
2024-06-10T09:54:41.8781768Z ##[error]Error: The process 'D:\AzDO_Services_xxxxxxxxxx\agent1\_work\_tool\dotnet\dotnet.exe' failed with exit code 1
2024-06-10T09:54:41.8803435Z Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://docs.microsoft.com/en-us/dotnet/core/tools/ and https://docs.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
2024-06-10T09:54:41.8804994Z ##[error]Dotnet command failed with non-zero exit code on the following projects : [ '' ]
2024-06-10T09:54:41.8923228Z ##[section]Finishing: DotNetCoreCLI

And then the content of the copied nuget.config (location after copy is the folder of the migration project file):

image

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="globalPackagesFolder" value="..\packages"/>
  </config>
  <solution>
    <add key="disableSourceControlIntegration" value="true"/>
  </solution>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3"/>
    <add key="xxxxxxxxxx Nexus" value="https://nexus.xxxxxxxxxxxxx.com/repository/xxxxxxxx_General_xxxxxxxx/index.json"/>
  </packageSources>
</configuration>