C
C#5mo ago
zorous

Installed Entity framework SQLite but getting this error in console

C:\Users\summi\source\repos\HHR Essentials\obj\HHR Essentials.csproj.EntityFrameworkCore.targets(4,5): error MSB4006: There is a circular dependency in the target dependency graph involving target "GetEFPr
ojectMetadata". [C:\Users\summi\source\repos\HHR Essentials\HHR Essentials.csproj]
Unable to retrieve project metadata. Ensure it's an SDK-style project. If you're using a custom BaseIntermediateOutputPath or MSBuildProjectExtensionsPath values, Use the --msbuildprojectextensionspath option.
C:\Users\summi\source\repos\HHR Essentials\obj\HHR Essentials.csproj.EntityFrameworkCore.targets(4,5): error MSB4006: There is a circular dependency in the target dependency graph involving target "GetEFPr
ojectMetadata". [C:\Users\summi\source\repos\HHR Essentials\HHR Essentials.csproj]
Unable to retrieve project metadata. Ensure it's an SDK-style project. If you're using a custom BaseIntermediateOutputPath or MSBuildProjectExtensionsPath values, Use the --msbuildprojectextensionspath option.
how do i fix this message? Im using the wpf template that vs provides by default. i get this error when i run the command: dotnet ef migrations add InitialCreate
63 Replies
zorous
zorousOP5mo ago
its saying there is an error in the file: "HHR Essentials.csproj.EntityFrameworkCore.targets" here its contents:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="GetEFProjectMetadata">
<MSBuild Condition=" '$(TargetFramework)' == '' "
Projects="$(MSBuildProjectFile)"
Targets="GetEFProjectMetadata"
Properties="TargetFramework=$(TargetFrameworks.Split(';')[0]);EFProjectMetadataFile=$(EFProjectMetadataFile)" />
<ItemGroup Condition=" '$(TargetFramework)' != '' ">
<EFProjectMetadata Include="AssemblyName: $(AssemblyName)" />
<EFProjectMetadata Include="Language: $(Language)" />
<EFProjectMetadata Include="OutputPath: $(OutputPath)" />
<EFProjectMetadata Include="Platform: $(Platform)" />
<EFProjectMetadata Include="PlatformTarget: $(PlatformTarget)" />
<EFProjectMetadata Include="ProjectAssetsFile: $(ProjectAssetsFile)" />
<EFProjectMetadata Include="ProjectDir: $(ProjectDir)" />
<EFProjectMetadata Include="RootNamespace: $(RootNamespace)" />
<EFProjectMetadata Include="RuntimeFrameworkVersion: $(RuntimeFrameworkVersion)" />
<EFProjectMetadata Include="TargetFileName: $(TargetFileName)" />
<EFProjectMetadata Include="TargetFrameworkMoniker: $(TargetFrameworkMoniker)" />
<EFProjectMetadata Include="Nullable: $(Nullable)" />
<EFProjectMetadata Include="TargetFramework: $(TargetFramework)" />
<EFProjectMetadata Include="TargetPlatformIdentifier: $(TargetPlatformIdentifier)" />
</ItemGroup>
<WriteLinesToFile Condition=" '$(TargetFramework)' != '' "
File="$(EFProjectMetadataFile)"
Lines="@(EFProjectMetadata)" />
</Target>
</Project>
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="GetEFProjectMetadata">
<MSBuild Condition=" '$(TargetFramework)' == '' "
Projects="$(MSBuildProjectFile)"
Targets="GetEFProjectMetadata"
Properties="TargetFramework=$(TargetFrameworks.Split(';')[0]);EFProjectMetadataFile=$(EFProjectMetadataFile)" />
<ItemGroup Condition=" '$(TargetFramework)' != '' ">
<EFProjectMetadata Include="AssemblyName: $(AssemblyName)" />
<EFProjectMetadata Include="Language: $(Language)" />
<EFProjectMetadata Include="OutputPath: $(OutputPath)" />
<EFProjectMetadata Include="Platform: $(Platform)" />
<EFProjectMetadata Include="PlatformTarget: $(PlatformTarget)" />
<EFProjectMetadata Include="ProjectAssetsFile: $(ProjectAssetsFile)" />
<EFProjectMetadata Include="ProjectDir: $(ProjectDir)" />
<EFProjectMetadata Include="RootNamespace: $(RootNamespace)" />
<EFProjectMetadata Include="RuntimeFrameworkVersion: $(RuntimeFrameworkVersion)" />
<EFProjectMetadata Include="TargetFileName: $(TargetFileName)" />
<EFProjectMetadata Include="TargetFrameworkMoniker: $(TargetFrameworkMoniker)" />
<EFProjectMetadata Include="Nullable: $(Nullable)" />
<EFProjectMetadata Include="TargetFramework: $(TargetFramework)" />
<EFProjectMetadata Include="TargetPlatformIdentifier: $(TargetPlatformIdentifier)" />
</ItemGroup>
<WriteLinesToFile Condition=" '$(TargetFramework)' != '' "
File="$(EFProjectMetadataFile)"
Lines="@(EFProjectMetadata)" />
</Target>
</Project>
Pobiega
Pobiega5mo ago
Can you show your .csproj file?
leowest
leowest5mo ago
and sln file
zorous
zorousOP5mo ago
idk where that is
No description
leowest
leowest5mo ago
looks like .net framework project
zorous
zorousOP5mo ago
leowest
leowest5mo ago
u double click the project icon and it should open the csproj please use $paste
MODiX
MODiX5mo ago
If your code is too long, you can post to https://paste.mod.gg/, save, and copy the link into chat for others to see your shared code!
zorous
zorousOP5mo ago
BlazeBin - qnmewynawhsp
A tool for sharing your source code with the world!
leowest
leowest5mo ago
or if ur project is on github that would be easier
Pobiega
Pobiega5mo ago
Yarp, this is ye olde framework
zorous
zorousOP5mo ago
im running the 4.8 framework
No description
Pobiega
Pobiega5mo ago
Can we ask why? Its outdated and dead since 2017
zorous
zorousOP5mo ago
default wpf template when creating
leowest
leowest5mo ago
well there is default wpf for .net 8
Pobiega
Pobiega5mo ago
$newproject
MODiX
MODiX5mo ago
When creating a new project, prefer using .NET over .NET Framework, unless you have a very specific reason to be using .NET Framework. .NET Framework is now legacy code and only get security fix updates, it no longer gets new features and is not recommended. https://cdn.discordapp.com/attachments/569261465463160900/899381236617855016/unknown.png
leowest
leowest5mo ago
which is the newer one
zorous
zorousOP5mo ago
i picked this when creating
No description
Pobiega
Pobiega5mo ago
Mhm You shouldn't have 🙂
zorous
zorousOP5mo ago
restart project?
Pobiega
Pobiega5mo ago
I would say so, yes
zorous
zorousOP5mo ago
which one do i pick?
zorous
zorousOP5mo ago
??
No description
Pobiega
Pobiega5mo ago
Yes
leowest
leowest5mo ago
the one that does not have "Framework" in the name basically anything tagged as .net framework means its legacy code now and unless you have a specific requirement that makes u use it, u should avoid it
zorous
zorousOP5mo ago
didnt know, mb
leowest
leowest5mo ago
its ok glad u learned before u progressed too deep into it
zorous
zorousOP5mo ago
can we keep this thread if i face the issue again?
Pobiega
Pobiega5mo ago
Yup
zorous
zorousOP5mo ago
:kekw: already created 75% of my UI
Pobiega
Pobiega5mo ago
Make sure you install the correct version of EF thou You can copy the xaml over
zorous
zorousOP5mo ago
i have .net 8
leowest
leowest5mo ago
you could keep it but I strongly suggest you $close this one and open a new one with your specific problem which would be less cluttered for anyone to help u
MODiX
MODiX5mo ago
If you have no further questions, please use /close to mark the forum thread as answered
Pobiega
Pobiega5mo ago
You'll be fine
zorous
zorousOP5mo ago
i should be fine to use the latest v8 bc i have .net 8?
leowest
leowest5mo ago
yep
Pobiega
Pobiega5mo ago
Yes
zorous
zorousOP5mo ago
bet
leowest
leowest5mo ago
u can do dotnet --info to confirm if you're unease
Pobiega
Pobiega5mo ago
If you tried using that with the current project, that's why it's not workinf EfCore is only for modern .net Not framework
zorous
zorousOP5mo ago
all good
No description
leowest
leowest5mo ago
also
zorous
zorousOP5mo ago
hmm?
leowest
leowest5mo ago
https://learn.microsoft.com/en-us/ef/core/get-started/overview/first-app?tabs=visual-studio might be helpful if u dont already usually u want Microsoft.EntityFrameworkCore.Sqlite Microsoft.EntityFrameworkCore.Tools Microsoft.EntityFrameworkCore.Design if u plan on using migrations
zorous
zorousOP5mo ago
also how do i place the db in the same place as the .exe file when building? bc when creating and writing its in the /data/.db
leowest
leowest5mo ago
if u look at the example in the link above
public BloggingContext()
{
var folder = Environment.SpecialFolder.LocalApplicationData;
var path = Environment.GetFolderPath(folder);
DbPath = System.IO.Path.Join(path, "blogging.db");
}

// The following configures EF to create a Sqlite database file in the
// special "local" folder for your platform.
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite($"Data Source={DbPath}");
public BloggingContext()
{
var folder = Environment.SpecialFolder.LocalApplicationData;
var path = Environment.GetFolderPath(folder);
DbPath = System.IO.Path.Join(path, "blogging.db");
}

// The following configures EF to create a Sqlite database file in the
// special "local" folder for your platform.
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite($"Data Source={DbPath}");
Pobiega
Pobiega5mo ago
Just add relative to your root directory, then set it to "copy if newer"
leowest
leowest5mo ago
by setting DbPath to simple "blogging.db" it would do that already
zorous
zorousOP5mo ago
alr thx
leowest
leowest5mo ago
so instead of the above just
public BloggingContext()
{
DbPath = "blogging.db";
}

// The following configures EF to create a Sqlite database file in the
// special "local" folder for your platform.
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite($"Data Source={DbPath}");
public BloggingContext()
{
DbPath = "blogging.db";
}

// The following configures EF to create a Sqlite database file in the
// special "local" folder for your platform.
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite($"Data Source={DbPath}");
what Pobiega said above would be the preferable way of doing it because it would persist the information in your db across builds
zorous
zorousOP5mo ago
that does seem easier
Pobiega
Pobiega5mo ago
This assumes you have data before the app starts for the first time
leowest
leowest5mo ago
so it would be mmm I think DbPath = "../../../blogging.db"; (assuming u dont set the file to copy if newer) if u do u can keep the above instead with just blogging.db)
Pobiega
Pobiega5mo ago
Ie, your project contains a pre-migrated database If you dont, then just let ef create it I'd probably recommend just adding a seeder to your app however
zorous
zorousOP5mo ago
wdym by "seeder"
Pobiega
Pobiega5mo ago
Makes it a lot easier to upgrade without losing data A method that adds any initial data if the tables are empty after migrations
zorous
zorousOP5mo ago
how do i properly add a sqlite3 database which will store data from an api i have
leowest
leowest5mo ago
that is too broad... this explains how u can use SQLite in your application https://discord.com/channels/143867839282020352/1265904711639498753/1265908523305537566
leowest
leowest5mo ago
beyond would be u querying your api and storing it to the database
Want results from more Discord servers?
Add your server