When you’re building a .Net liibrary you have to take in care which framework the end user will use. In order to avoid user’s framework upgrade/downgrade we must target multiple frameworks in the nuget package.
Library project configuration
First, in your .csproj file, create separate build configurations. I created “Debug” | “Release” and “Debug45” | “Release45” for the target frameworks 4.6.1 and 4.5 respectively. I manually set the OutputPath and added theTargetFrameworkVersion element to each configuration:
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug45|AnyCPU'">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release45|AnyCPU'">
In this way you can build the library with different target framework.
Targeting Multiple Frameworks in NuGet
In the folder created for the nuget package divide the lib folder by adding for each targeted framework the relative folder where you will add the relative library .dll file.
The lib folder looks like this:
Now you can run nuget.exe pack MyAssembly.nuspec
A new package is created.
When you refer this package through Nuget package manager from a VS solution, your reference automatically link the dll related to your project framework.
There are a number of situations when you need to reinstall and update nuget packages for a VS project.
One of this situations is when you wanna upgrade or downgrade the .NET Framework.
In this situation the most important Nuget functionality is Reinstalling packages with dependencies:
reinstalls the same version of the original package, but installs the latest version of dependencies unless specific version constraints are provided. This allows you to update only the dependencies as required to fix an issue. However, if this rolls a dependency back to an earlier version, you can use
to reinstall that one dependency without affecting the dependent package.
For more informations please visit:
Downloading this tool you must use the remote debugger for Visual Studio 2015.
Visual Studio 2015 remote tools – Direct download link
In order to revert to a previous migration run this comman on the “Package Manager Console”
If you need to revert to the first one run this command
In order to stash untracked file you can use this command
git stash save -u
In order to create a new locally database to run tests you can create your migrations in the test project by taking in care that you can use your repository db context in another VS project.
To achieve this result you can do the following in the Package Manager Console
Enable-Migrations -ContextProjectName MyProject.Repository -ContextTypeName MyProject.Repository.MyDbContext -ProjectName MyProject.Tests -StartUpProjectName MyProject.Tests -ConnectionStringName "MyConnectionString"
Add-Migration "Init Test Db"
Update-Database -ProjectName MyProject.Tests -StartUpProjectName MyProject.Tests -ConnectionStringName "MyConnectionString"
In order to update the .gitignore file do the following:
Commit the new .gitignore file.
Run these commands:
git rm -r –cached .
git add .
git commit -m “.gitignore update”
Push on the remote branch.