C
C#4mo 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
zorousOP4mo 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
Pobiega4mo ago
Can you show your .csproj file?
leowest
leowest4mo ago
and sln file
zorous
zorousOP4mo ago
idk where that is
No description
leowest
leowest4mo ago
looks like .net framework project
zorous
zorousOP4mo ago
leowest
leowest4mo ago
u double click the project icon and it should open the csproj please use $paste
MODiX
MODiX4mo 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
zorousOP4mo ago
BlazeBin - qnmewynawhsp
A tool for sharing your source code with the world!
leowest
leowest4mo ago
or if ur project is on github that would be easier
Pobiega
Pobiega4mo ago
Yarp, this is ye olde framework
zorous
zorousOP4mo ago
im running the 4.8 framework
No description
Pobiega
Pobiega4mo ago
Can we ask why? Its outdated and dead since 2017
zorous
zorousOP4mo ago
default wpf template when creating
leowest
leowest4mo ago
well there is default wpf for .net 8
Pobiega
Pobiega4mo ago
$newproject
MODiX
MODiX4mo 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
leowest4mo ago
which is the newer one
zorous
zorousOP4mo ago
i picked this when creating
No description
Pobiega
Pobiega4mo ago
Mhm You shouldn't have 🙂
zorous
zorousOP4mo ago
restart project?
Pobiega
Pobiega4mo ago
I would say so, yes
zorous
zorousOP4mo ago
which one do i pick?
zorous
zorousOP4mo ago
??
No description
Pobiega
Pobiega4mo ago
Yes
leowest
leowest4mo 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
zorousOP4mo ago
didnt know, mb
leowest
leowest4mo ago
its ok glad u learned before u progressed too deep into it
zorous
zorousOP4mo ago
can we keep this thread if i face the issue again?
Pobiega
Pobiega4mo ago
Yup
zorous
zorousOP4mo ago
:kekw: already created 75% of my UI
Pobiega
Pobiega4mo ago
Make sure you install the correct version of EF thou You can copy the xaml over
zorous
zorousOP4mo ago
i have .net 8
leowest
leowest4mo 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
MODiX4mo ago
If you have no further questions, please use /close to mark the forum thread as answered
Pobiega
Pobiega4mo ago
You'll be fine
zorous
zorousOP4mo ago
i should be fine to use the latest v8 bc i have .net 8?
leowest
leowest4mo ago
yep
Pobiega
Pobiega4mo ago
Yes
zorous
zorousOP4mo ago
bet
leowest
leowest4mo ago
u can do dotnet --info to confirm if you're unease
Pobiega
Pobiega4mo 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
zorousOP4mo ago
all good
No description
leowest
leowest4mo ago
also
zorous
zorousOP4mo ago
hmm?
leowest
leowest4mo 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
zorousOP4mo 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
leowest4mo 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
Pobiega4mo ago
Just add relative to your root directory, then set it to "copy if newer"
leowest
leowest4mo ago
by setting DbPath to simple "blogging.db" it would do that already
zorous
zorousOP4mo ago
alr thx
leowest
leowest4mo 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
zorousOP4mo ago
that does seem easier
Pobiega
Pobiega4mo ago
This assumes you have data before the app starts for the first time
leowest
leowest4mo 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
Pobiega4mo 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
zorousOP4mo ago
wdym by "seeder"
Pobiega
Pobiega4mo 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
zorousOP4mo ago
how do i properly add a sqlite3 database which will store data from an api i have
leowest
leowest4mo ago
that is too broad... this explains how u can use SQLite in your application https://discord.com/channels/143867839282020352/1265904711639498753/1265908523305537566
leowest
leowest4mo ago
beyond would be u querying your api and storing it to the database
Want results from more Discord servers?
Add your server