How do I make migrations in Entity Framework? - c#

My research keeps telling me to use the Migrate.exe, which has not shown up in my project, and it cannot be downloaded anywhere. I am also using VS Code and not Visual Studio, which seems to make it impossible to use the Package Manager Console.
And I am using Entity Framework - not Entity Framework Core - so I do not have all the options of EFC.
Currently I am trying to set Entity Framework up in Unity, the game engine. It was possible to set up a temporary project with Entity Framework v6.2.0 and run dotnet pack to get the EntityFramework.dll but it does not create the Migrate.exe. And it seems to be the only option for creating migrations.
Do any of you know how to get the Migrate.exe file or another way to add migrations?

When you install Entity Framework using NuGet migrate.exe will be inside the tools folder of the downloaded package. In \packages\EntityFramework.\tools
Source is microsoft
have you tried this?

Apparently there is a difference in installing and adding, not that they mention that when you look at the package on nuget.org.
So rather than running dotnet add package EntityFramework --version 6.2.0
I needed to download the latest nuget.exe from nuget.org and create a packages.config file in the root folder.
I then ran nuget.exe install packages.config -OutputDirectory packages which installed all the files I needed.
packages.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.2.0" targetFramework="net40" />
</packages>

Related

Wrong net-standard library version is restored by nuget/used by build

I have a solution where projects reference netcoreapp2.1, netstandard 2.0, net472, as targetframeworks.
Some have
<TargetFrameworks>netstandard2.0;net472</TargetFrameworks>
others have
<TargetFrameworks>netstandard2.0</TargetFrameworks>
others have
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
After I deleted the Nugetfallback folder because of unrelated problems, suddenly my build fails with hundreds of errors about netstandard library classes no longer being found, e.g.
C:\Windows\system32\config\systemprofile\.nuget\packages\netstandard.library\2.0.3\build\netstandard2.0\ref\System.Net.WebSockets.dll' could not be found.
what my build does basically boils down to:
nuget.exe locals all -clear
nuget.exe restore {MY_SOLUTION}
msbuild /restore {MY_SOLUTION}
Looking into the nuget/packages folder, I can see that the netstandard library exists after nuget restore, but in the
...\netstandard.library\2.0.0\ folder, and not in the
...\netstandard.library\2.0.3\
I've tried
deleting the nuget cache manually
using an explicit packagereference to the netstandardlibrary 2.0.3 in my csproj files,
but this hasn't helped.
The Solution Explorer in Visual Studio shows me that in the solution there are only dependencies to netstandard 2.0.3, none to 2.0.0
all the relevant packages.config files show
<package id="NETStandard.Library" version="2.0.3" targetFramework="net462" />
Why is the wrong version of the netstandard.library retrieved by nuget (2.0.0 instead of 2.0.3).
Where in my solution could I configure/change this? Could this be because of other libraries where I have the wrong version as dependency?
Thanks!
Reinstalling nuget, and installing a newer version of the dotnet SDK helped. No idea what caused it.

Creating NuGet using Team Foundation Server missing dependencies

I have created a simple class library in .net standard 2.0 with a few nuget dependencies like Dapper.
I am using Team Foundation Server 16 to then build and package the project. My issue is, that when I then browse to my new NuGet package, it does not list it's dependencies in the NuGet package manager in VS and I have to install them manually afterwards.
Creating a nuget package of the same class library from Visual Studio 2019 locally works as intended.
My build tasks on TFS are:
Use nuget 5.4.0
NuGet restore
Build solution
Run script (A .bat file for updating version number)
NuGet pack
Publish build artifact
The NuGet pack uses default settings with command "pack" and path pointing only to .csproj file.
Creating a nuget package of the same class library from Visual Studio
2019 locally works as intended.
It's one issue about nuget pack command. When you pack the .net standard project in VS locally, it(right-click=>pack button) actually calls dotnet cli instead of nuget.exe to do the pack job.
For now, nuget pack command can't work well with those projects that use PackageReference to manage nuget packages. (Including .net framework projects with PackageReference,.net core and .net standard projects).
More details see discussions here and here.
To resolve that issue(For TFS2017 and above):
Use dotnet pack command instead of nuget pack command. And for pipeline in tfs, use dotnet restore, build, pack tasks instead of nuget restore, nuget pack tasks.
Update1 for TFS2016:
Since TFS will run those tasks in tfs agents, one alternative way is to install .net core sdk manually, and then use command-line task to execute dotnet pack command to create nuget packages.
.net core sdk download link here.
Update2:
Also, we can still use nuget pack command/task. To include those dependencies, we need to create an extra xx.nuspec file with content similar to this:
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<id>PackageName</id>
<version>1.0.0</version>
<title>xxx</title>
<authors>xxx</authors>
<owners>xxx</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="expression">MIT</license>
<description>xxx</description>
<releaseNotes>xxx</releaseNotes>
<copyright>Copyright 2020</copyright>
<tags>Tag1 Tag2</tags>
<dependencies>
<dependency id="Dapper" version="1.30.0"/>
//define other dependencies manually here.
</dependencies>
</metadata>
</package>
Place this file in same directory where xx.csproj exists, and then nuget pack command/task can now create the package with dependencies.

target framework considerations with nuget packages?

I'm fairly new to the process of creating NuGet packages. I recently created a NuGet package via NuGetPackageExplorer. The "Package Metadata" view has a "Framework Assembly References" section with a value of "Microsoft.CSharp (Any,Verion=0.0)." This is what the nuspec file looks like:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>My.Cool.NuGet.Package</id>
<version>1.0.2</version>
<title></title>
<authors>John Smith</authors>
<owners>John Smith</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>My cool NuGet package</description>
<frameworkAssemblies>
<frameworkAssembly assemblyName="Microsoft.CSharp" />
</frameworkAssemblies>
</metadata>
</package>
Can you please explain relationships, dependencies and constraints for the following dimensions:
Target Framework version of the source .NET project for the NuGet package
frameworkAssemblies section of the nuspec file
Target Framework version of the project which installs the NuGet package
The frameworkAssembly value in the nuspec above is displayed as follows in the NuGetPackageExplorer:
Assembly name: Microsoft.CSharp
Supported frameworks: Any,Version=v0.0
Does this mean that the NuGet package is intended to be .NET framework version agnostic? Are there any scenarios where I would want to explicitly state a specific version(s) in this section? The reason I'm asking is that I installed a NuGet package in an MVC project yesterday and I was experiencing some weird behavior. Specifically:
The NuGet package showed as installed and displayed in the References list
I was able to add a using directive to the namespace of the NuGet package
However, when I attempted to run the app, the compiler displayed an error of "type of namespace not found" for these using directives. But then the compiler errors disappeared but the app wouldn't run b/c of the previous compiler errors. After I fiddled with the version settings with the MVC project and NuGet package source project, I was able to get around this error. So now I'm trying to get an understanding of the finer details of what I need to consider and configure in regards to target frameworks.
The TargetFamework of the source project for the NuGet package should be the lowest framework version you need by projects that will install it. For example if you know you will have projects in the 4.5 and 4.6 framework you make the source for the package 4.5. You can also put multiple builds for multiple frameworks inside a package. Here is the documentation about that.
The TargetFramework for the projects installing the package should be greater or equal that the version of the package. Since higher versions of the framework are compatible with lower versions. It should not allow you to install a package that is not supporting the framework you are using in the project.
The frameworkAssemblies sections just defines which framework assemblies a package is using so the references are automatically added. Check the documentation for more detailed info.

Why nuget from VSTS nuget feed wants to install the same package multiple times and throwing error?

I have a REST Api implemented using Durable Function App in Azure, which uses netstandard2.0, and I have other class libraries in this solution also using netstandard2.0. One of them is contracts projects.
There is another solution where the UAT tests placed for this solution. The reason for this is that Specflow is still not available for .Net Core, it is available for .Net Framework only. Being able to test the Api I need the contracts for the Api. That is the reason I need to include the REST Api solution Contracts project (this one is netstandard2.0). This dependency is managed by nuget.
When I would like to install the Contracts package (using netstandard2.0) in Specflow project (which uses .Net Framework 4.7.1) I get the error below.
What I tried:
I restarted Visual Studio a few times because I experienced that sometimes it gets crazy when .Net Core or .Net Standard projects are in use. Restarting did not help.
I opened the project from JetBrains Rider, but it did not see the netstandard2.0 nuget package in the repository. I believe it is due to that the project uses .Net Framework 4.7.1 and not Net Standard 2.0
I saw the error Cannot create "C:\...\REST.Api.dll" because a file or directory with the same name already exists.. So, I deleted all packages under the solution packages directory. I also deleted cache in Visual Studio. But, the next time I started Visual Studio and tried to install package the same error occurred again.
I also tried to install package using console on my machine (nuget.exe install ...). The error is the same.
How it is possible to resolve this issue? I read that from .Net Framework 4.6 and above and .Net Core it is possible to reference .Net Standard libraries.
Attempting to gather dependency information for package 'REST.Api.1.0.0-20180305-154726' with respect to project 'MasterData.Features.HttpClient', targeting '.NETFramework,Version=v4.7.1'
Gathering dependency information took 861.8 ms
Attempting to resolve dependencies for package 'REST.Api.1.0.0-20180305-154726' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'REST.Api.1.0.0-20180305-154726'
Resolved actions to install package 'REST.Api.1.0.0-20180305-154726'
GET https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg
Retrieving package 'REST.Api 1.0.0-20180305-154726' from 'Sayusi Ando's Digital Library Packages'.
OK https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg 2343ms
Installing REST.Api 1.0.0-20180305-154726.
Error downloading 'REST.Api.1.0.0-20180305-154726' from 'https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg'.
Cannot create "C:\Users\username\.nuget\packages\REST.api\1.0.0-20180305-154726\lib\netstandard2.0\REST.Api.dll" because a file or directory with the same name already exists.
GET https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg
OK https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg 462ms
Installing REST.Api 1.0.0-20180305-154726.
Error downloading 'REST.Api.1.0.0-20180305-154726' from 'https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg'.
Cannot create "C:\Users\username\.nuget\packages\REST.api\1.0.0-20180305-154726\lib\netstandard2.0\REST.Api.dll" because a file or directory with the same name already exists.
GET https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg
OK https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg 464ms
Installing REST.Api 1.0.0-20180305-154726.
Install failed. Rolling back...
Package 'REST.Api.1.0.0-20180305-154726' does not exist in project 'MasterData.Features.HttpClient'
Package 'REST.Api.1.0.0-20180305-154726' does not exist in folder 'C:\VSTS\REST.QA.Features\src\packages'
Executing nuget actions took 3.51 sec
Error downloading 'REST.Api.1.0.0-20180305-154726' from 'https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg'.
Cannot create "C:\Users\username\.nuget\packages\REST.api\1.0.0-20180305-154726\lib\netstandard2.0\REST.Api.dll" because a file or directory with the same name already exists.
Time Elapsed: 00:00:05.5462783
The root of the problem is that the target properties conflicted with another filename. (names are shortened)
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<!-- package stuff -->
<dependencies>
<group targetFramework=".NETStandard2.0" />
</dependencies>
</metadata>
<files>
<file src="..." target="lib\netstandard2.0\Contracts.dll" />
<file src="..." target="lib\netstandard2.0\Contracts.dll" />
<file src="..." target="lib\netstandard2.0\Contracts.dll" />
</files>
</package>

Package Manager Console Warning - There is already a version of EntityFramework.dll loaded. You may need

Using VS 2015 Community (but this is also happening in VS2013)
.NET 4
EF 4.3.1 originally installed via nuget
Package Manager Console Host Version 3.2.0.10516
In the package manager console I get this warning when I start up one of my projects
There is already a version of EntityFramework.dll loaded. You may need
to restart Visual Studio for the commands to work properly.
The only refererence to Entity Framework in Packages.config is
<package id="EntityFramework" version="4.3.1" targetFramework="net40" />
Which seems good.
Anyone know whats going on?

Categories

Resources