I have installed entity framework v 6.0.0.0 nuget package.
When building solution locally, it works great without any issues. But, when I check in the code and when the build runs on server, it throws below compilation error.
Primary reference "EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL".
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
Any suggestions would be appreciated. Thank you in advance.
The problem you probably have is that your build agent isn't fetching the Nuget package for you.
In my company this is caused by the service account that the build agent is running under not having the corporate proxy set by default.
So firstly you need to run the build agent service as a real user (i.e. not Network Service or Local Service). Then you need to log in to the build agent as that user and set the proxy by hand. Hopefully you can use your own proxy settings.
It's been a long time since I did this, but I also seem to remember that there might be some Visual Studio setting that is off by default about Nuget package restore. So what I generally do when I'm troubleshooting this kind of thing is try to build the solution as the build agent user on the build agent from within Visual Studio. Once you can do that successfully the build should work. It should also work as you add Nuget packages.
If this completely fails to work because you can't get the build agent user through the proxy then you can always create a local Nuget file share and copy the packages to that share, then add the share to your Nuget config. This is configured in the nuget.config file. Mine looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<packageSources>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<add key="Private package source" value="\\BuildController\nuget\Packages" />
</packageSources>
</configuration>
The second package source is a file share where we put our own packages.
Probably the versions are not updated properly , Uninstall and reinstall entity framework from Nuget Package Manager and make sure that package.config and web.config has the same version that's present in your reference / bin .
Related
When developing in Visual Studio 2017, I use a combination of the standard NuGet package source, and package sources from the company I work for.
To access those company package sources, I have to connect to our company VPN.
Unfortunately, this means I have to always be connected to our company VPN, no matter what I'm developing, because otherwise NuGet gives me this:
Exception 'System.AggregateException' thrown when trying to add source 'http://[one of my company's package sources]'. Please verify all your online package sources are available.
One or more errors occurred.
Unable to load the service index for source http://[one of my company's package sources].
An error occurred while sending the request.
The remote name could not be resolved: '[one of my company's package sources]'
This would make sense if I'm trying to use a package only hosted on my company's servers. But even if I specifically set the Package source dropdown to nuget.org, I get this error.
There's an issue to fix it, but it's two years old and shows no signs of activity: install fails when a nuget Source is unavailable even when this is not the selected Source #2614
So, is there a way somehow to configure NuGet to ignore missing package sources?
As explained in this answer, the behavior of Visual Studio 2017 is by design, but maybe you can use a custom nuget.config as a workaround (also explained in that answer).
Here's how to config NuGet to ignore some sources.
If you have all your non-company code in a single folder structure, then in the root you can put a nuget.config file that looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<disabledPackageSources>
<add key="My Company's NuGet Source" value="true" />
</disabledPackageSources>
</configuration>
If you're not sure what that key should be, run nuget sources from the command line:
>nuget sources
Registered Sources:
1. nuget.org [Enabled]
https://api.nuget.org/v3/index.json
2. My Company's NuGet Source [Disabled]
https://path/to/the/nuget
3. Microsoft Visual Studio Offline Packages [Enabled]
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
This is also a good way to verify that the nuget.config is being detected. The Disabled is from my nuget.config file; if I run nuget sources in my company code folder, number 2 shows as Enabled.
You can find full details about the structure of nuget.config here:
nuget.config reference
Does anybody know how to add custom package source to Visual Studio Code?
E.g. I'd like to add https://www.myget.org/F/aspnet-contrib/api/v3/index.json as a package source and drive these packages through project.json.
To add to the answer, adding a nuget.config in the project solves it for the project. Adding to the root is ok. The config could look like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="MyGet" value="https://www.myget.org/F/aspnet-contrib/api/v3/index.json" />
</packageSources>
</configuration>
Another option that worked for me and was actually needed as part of my CI/CD pipeline is to use dotnet nuget add source <repo-url> --name <repo-name>
Simply call that before you call dotnet restore or dotnet build
Reference:
https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-add-source
Note - if your custom package source is password protected, then the credentials should also be part of the config file.
<packageSourceCredentials>
<MyGet> <!--package src name-->
<add key="Username" value="something" />
<add key="ClearTextPassword" value="thepassword" />
</MyGet>
</packageSourceCredentials>
And for anyone wondering why the credentials have to be in clear text (which defeats the whole purpose of having credentials in the first place, since this config file will also go into source control).
This is an open issue in dotnet / nuget cli. Ref github issue # 5909 & 1851
You can add a NuGet.config file and specify the package source in there. Some reference docs: https://learn.microsoft.com/en-us/nuget/schema/nuget-config-file
I want to install a design time plugin for a visual studio extension (ie runs when using visual studio, and not when the application is running). This requires that I modify the app.config with an entry that points at the dll containing the extension code. The plugin is installed via nuget and if I add this dll to a folder under the project and use a fixed path in the app.config.install.xdt then everything work ok. However what I want is for the xdt to insert a value which points to the dll in the packages folder, where it gets installed via nuget. My problem is that the relative path to the nuget folder is not fixed for the projects. Each project may be in a different folder (several folders deep inside the solution folder) and not just in a direct child of the solution folder, so I want to be able to use some variable in my xdt.
Currently I have this in my xdt:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<specFlow>
<plugins xdt:Transform="InsertIfMissing">
<add name="NCrunch.Generator" path=".\SpecflowPlugins\" type="Generator" xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)"/>
</plugins>
</specFlow>
</configuration>
but I want something like this:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<specFlow>
<plugins xdt:Transform="InsertIfMissing">
<add name="NCrunch.Generator" path="$(SolutionDir)\packages\Specflow.Ncrunch.1.0.0\lib\net" type="Generator" xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)"/>
</plugins>
</specFlow>
</configuration>
is this possible in xdt? if not is there another option for getting this to munge the app.config correctly when my nuget package installs?
The XDT syntax doesn't allow replacement tokens such as the one you put in your example.
One option I can think of would be to modify the app.config.install.xdt file in your init.ps1 PowerShell script, replacing the tokens for the actual values before the XDT transform is applied by NuGet.
For more information regarding init.ps1 see: Creating and Publishing a Package
I have added a NuGet package to my solution and enabled package restore on the solution. This correctly created the .nuget folder with targets file etc.
The NuGet package is actually another project which becomes a dependency in the solution. Initially I added this package to the solution manually.
To Test this NuGet feature, I deleted the folder underneath the packages folder.
At that point I then get compiler errors obviously because other dependent projects are reliant on the project that has just been removed.
When I build the solution, I'm expecting NuGet to go and download the NuGet packages that it requires is this is set to Enable Package Restore, and then build successfully as all other dependent projects can now build.
However, I see no evidence of the NuGet package from being downloaded in the output, and the build errors remain the same as if the project hasn't been downloaded.
Can anyone confirm whether there is something I am missing or am doing wrong here?
To my knowledge deleting packages under the packages folder should be restored by NuGet's package restore feature.
It would be helpful to:
See the actual build error.
Know which packages you are trying to restore.
Some packages, such as ours, rely on .targets files which have issues when being used in package restore.
Make sure that NuGet.Config in your solution folder has "packageRestore" option enabled:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
</packageRestore>
</configuration>
Also it should be enabled globally in "C:\Users\%UserName%\Application Data\NuGet\NuGet.Config" (it can be set from within VS, Tools->Options->Package Manager.
Also note that there's another approach for restoring package since NuGet 2.7 - "Automatic Package Restore". See doc for more info: http://docs.nuget.org/docs/reference/package-restore and http://docs.nuget.org/docs/workflows/migrating-to-automatic-package-restore
I have the following setup in my solution's .nuget/Nuget.Config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<config>
<add key="repositoryPath" value="C:\Xos\packages\" />
</config>
</configuration>
The point of this is to try and make Nuget package restore manageable, and share packages across our many solutions. I then went into my current solution's packages directory and deleted all the packages (so they would instead restore them to C:\Xos\packages). I then closed VS 2012 and reloaded the solution and rebuilt.
However, all my packages are being restored in my solution's packages directory, NOT the directory specified in repositoryPath configuration.
What am I doing wrong?
I had the same issue with VS2015 RC. One of two things suddenly made it work:
(1) I checked-out the project file from source control, and completely closed Visual Studio (not just the solution).
(2) I edited the csproj file and noticed that the entry for packages.config had a <SubType>Designer</SubType> inner tag, which I removed.
I suspect it was the close-down of Visual Studio...
This appears to be a bug and is fixed in 2.3 (which doesn't appear to be released yet).
Until then I modified my Nuget.Targets as described in that bug and using that for now.