© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
2 replies
Indeed

DotnetCLI Get Project Root Path - Database Recreation Script

Set-Location (get-item $PSScriptRoot).Parent.Parent.FullName
dotnet ef database drop --context LogDbContext
dotnet ef migrations remove --context LogDbContext 
$dbPath = Join-Path $PSScriptRoot \LogDatabase.sqlite
$dbExists = Test-Path -Path $dbPath -PathType Leaf
if ($($dbExists)) {
    (Get-ChildItem $($dbPath)).Delete()
}
dotnet ef migrations add Initial -o ./Logging/Database/Migrations --context LogDbContext
dotnet ef database update --connection "Data Source=$($PSScriptRoot)\LogDatabase.sqlite" --context LogDbContext
Set-Location (get-item $PSScriptRoot).Parent.Parent.FullName
dotnet ef database drop --context LogDbContext
dotnet ef migrations remove --context LogDbContext 
$dbPath = Join-Path $PSScriptRoot \LogDatabase.sqlite
$dbExists = Test-Path -Path $dbPath -PathType Leaf
if ($($dbExists)) {
    (Get-ChildItem $($dbPath)).Delete()
}
dotnet ef migrations add Initial -o ./Logging/Database/Migrations --context LogDbContext
dotnet ef database update --connection "Data Source=$($PSScriptRoot)\LogDatabase.sqlite" --context LogDbContext


This is my sqlite database recreation script. I would like to change the first line to rather than go two levels up (script rn is in
Project/Logging/Database
Project/Logging/Database
) get somehow the project path (later i'll add the if checks for 2nd and 3rd line)
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Project Path
C#CC# / help
4y ago
❔ How to get file path of PDFs in project.
C#CC# / help
3y ago
❔ PlayStation 2 startup recreation
C#CC# / help
3y ago
✅ Serializing a dictonary without path in root object
C#CC# / help
3y ago