Entity Framework with NuGet - Import-Module error in init.ps1 - visual-studio

Here is the complete error message that I get in the Package Manager Console when starting VS2010:
Import-Module : The specified module
'C:\Users\adam.assman\Project\packages\EntityFramework.4.3.1\tools\EntityFramework.psd1'
was not loaded because no valid module file was found in any module
directory. At
C:\Users\adam.assman\Project\packages\EntityFramework.4.3.1\tools\init.ps1:13
char:14
I've installed Entity Framework using NuGet, on a DLL/ClassLibrary project in my solution. The startup project is referencing and using this DLL project. I therefore tried running the startup command from the console with the DLL project selected in the dropdown "Default Project", but that gives me the same error message.
I have NuGet version 1.6.21215.9133 (and obviously EF version 4.3.1).
If I try to run the command "Enable-Migrations -EnableAutomaticMigrations", I get a CommandNotFoundException and I suppose it's a result from the init error. I'm trying to accomplish the simplest form of the automatic migrations, using this guide: http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-automatic-migrations-walkthrough.aspx

I have no idea what was wrong, but I finally fixed this by editing the file init.ps1 inside the folder \packages\EntityFramework.4.3.1\tools.
I changed this line:
Import-Module (Join-Path $toolsPath 'EntityFramework.psd1') -ArgumentList $installPath
Into this:
Import-Module '.\packages\EntityFramework.4.3.1\tools\EntityFramework.psd1' -ArgumentList $installPath

Related

The specified deps.json [] does not exist

I'm using Asp.net Core with EntityFramework.Core. I'm having troubleshot migrations and Scaffold after format my pc.
when I write these in Package Manager Console
Scaffold-DbContext "Data Source=.\SQL2017DEV;Initial Catalog=MyDataBase;Integrated Security=True" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Db
Add-Migration Initial
error is
"The specified deps.json [D:\TFS\Erdi\Erdi\AspCoreWeb.Site\AspCoreWeb.Site.deps.json] does not exist"
[MyProjectFolder]\AspCoreWeb.Site.deps.json
I think it try to find my debug folder.
This solutioun is working other computers
I'm repair my visual studio but it hasn't changed
In my case; was fixed by changing the Startup Project (via Solution Properties) to the project that has EF Context file.
There is an issue with migration in VS2019. I have been facing a similar issue and was getting below error:
The specified deps.json [YourProjectLocation]\ProjectName.deps.json doesn't exists.
When I used dotnet CLI for migrations and it worked and was able to generate migration and update the same using dotnet CLI.
dotnet ef migrations add InitialCreate
dotnet ef database update
this problem generally occurs because of path issues. You should change your "outputPath" in the "project.assets.json" file.
D:\TFS\Erdi\Erdi\AspCoreWeb.Site\AspCoreWeb.Site.deps.json] instead of this,
D:\TFS\Erdi\Erdi\AspCoreWeb.Site\obj\AspCoreWeb.Site.deps.json]
i think this will resolve your problem.
If you are using Package Manager Console to "Add-Migration" or "Update-Database", be sure that the project where you want the migration is selected as the Startup project in Visual Studio and this project is also the default in Package Manager Console.
Solution Explorer:
Package Manager Console:
If you are using the dotnet CLI, then you have to navigate to the right project folder and run the migration commands from there.
Make sure that the Startup Project is where the connection string is and select the project in the Default project of Package Manager Console where the db context is at.
Just Go to VS 2022
It Worked for me
go to bin folder and copy files in it include deps.json to the path that see in error.

How to use Package Manager Console powershell outside visual studio

I have a powershell script which has nuget commands like:
Get-Project -All
Get-Package -ProjectName
When I run package manager console on visual studio like:
PM> .\download-packages-license.ps1
It worked but I cannot run powershell. I need a hlp.
Powershell error message:
download-packages-license.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/
fwlink/?LinkID=135170.
At line:1 char:1
+ .\download-packages-license.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
How to use Package Manager Console powershell outside visual studio
I am afraid you could not use Package Manager Console powershell outside visual studio. That because package manager console is providing is access to visual studio objects:
https://github.com/NuGet/Home/issues/1512
So, if you want use Package Manager Console powershell outside visual studio, we have to parse the .csproj file or .sln solution file with powershell manually, like:
How do I programmatically list all projects in a solution?
Hope this helps.

The Dnx Runtime package needs to be installed - hosted Build Controller

I am developing my first ASP.NET 5 Application and I have some problems with hosted build on Visual Studio Team Services (was Visual Studio Online). I get the error:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DNX\Microsoft.DNX.targets(126,5): Error : The Dnx Runtime package needs to be installed.
One row before I see following Build message:
Cannot find DNX runtime dnx-clr-win-x86.1.0.0-beta8 in the folder: C:\Users\buildguest.dnx\runtimes
I found the solution with Prebuild-Powershell script (https://msdn.microsoft.com/Library/vs/alm/Build/azure/deploy-aspnet5)
Note: I added the ASP.Net 5 MVC Project to an existing solution. I have no global.json file and src folder! This is the reason why I have adapted the script as follows:
& iex((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))
$dnxVersion = "latest"
& $env:USERPROFILE\.dnx\bin\dnvm install $dnxVersion -Persistent
Get-ChildItem -Path $PSScriptRoot\..\InternalWeb.Client -Filter project.json -Recurse | ForEach-Object { & dnu restore $_.FullName 2>1 }
The script runs after Build step "Get sources" and has following output:
But, I get still the same error message! What's wrong?
Thanks for help!
Michael
I ran into the same problem and I found a solution that worked for me.
The PowerShell script installs the latest runtime or the one that you have specified in your global.json file. Since it did not work without a global.json file and the default settings, I added a global.json file to my project folder and specified the version that I am using:
{
"sdk": {
"version": "1.0.0-rc1-update1",
"runtime": "coreclr",
"architecture": "x86"
}
}
The first try failed again with the following error:
The expected lock file doesn't exist. Please run "dnu restore" to generate a new lock file.
So I added dnu restore to the end of the PowerShell script.
The next build was successful. May be this works for you too.

Open file in visual studio via nuget manager console

context information
I Use the scaffolder nuget package to make database upgrade classes. by calling scaffold dbupgrade in the package manager console.
De upgrade powershell file ends with: Add-ProjectItemViaTemplate ....
What i want
It all works great and generates a class for me and adds it to the project file but: I would like to open the generated file in my solution.
Is this possible? and how would i go from here?
I use visual studio 2015 Community edition.
What I tried
I tried commands such as Open-File, Open-Document but these do not exist.
I found my solution on another stackoverflow question: https://stackoverflow.com/a/28426592/1275832
the solution would be:
$DTE.ExecuteCommand("File.OpenFile", "App.config")
For a nuget package Install.ps1 you could do:
param($installPath, $toolsPath, $package, $project)
//Get specific file
$file = $project.ProjectItems.Item("`$rootnamespace`$.nuspec")
//Get its location
$location = $proj.ProjectItems.Item("App.config").Properties['LocalPath'].Value
//Open the file in the IDE
$project.DTE.ExecuteCommand("File.OpenFile", $location)

Could not write destination file: Access to path 'd:\a\src\...\Web.config' is denied

I have a tfs project on visual studio online and created a build definition to compile this project. The project uses web config transformation. The build will be executed from the visual studio online hosted build controller and it fails because of the following error:
Could not write destination file: Access to path 'd:\a\src...\Web.config' is denied.
Any ideas how to resolve this issue?
Sounds like the classic problem of read-only files (see cannot modify .csproj files using build auto with tfs 13). Run a pre-build Powershell script that removes the attribute, something like this
Get-ChildItem -Include *.config -Recurse | foreach {
if ($_.IsReadOnly) { $_.IsReadOnly = $false }
}

Resources