I'm unable to find some nuget packages (VS 2019, asp.net core 2.2). I found that System.ComponentModels.Annotations can't be found in my .nuget folder and in VS, there is no "expand" arrow next to it like all the other packages:
In my .nuget folder:
I've tried clearing out my packages folder and re-building to get all the packages. I've tried update-package -reinstall. I've tried Installing system.componentmodel.annotations directly (rather than having it install as a dependency). My solution builds fine, but I can't find this package anywhere on my harddrive. I've also noticed that Microsoft.AspNetCore.Razor.Design is exhibiting the exact same behavior.
When NuGet restores a project that uses PackageReference for packages (all SDK-style projects, and opt-in for traditional projects), it writes the obj\project.assets.json file, which is what MSBuild uses to complete the rest of the build.
Looking at the packageFolders section of my test project, I see this:
"packageFolders": {
"c:\\git\\test\\globalPackages\\": {},
"C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder": {}
},
note that I have a nuget.config that redirects my global packages folder away from my user profile global packages folder, so temporary/fake packages I create don't pollute my real dev environment. FYI in case you're wondering why you don't see c:\users\zivkan\.nuget\packages.
But notice that there are two package folders.
Looking for System.ComonentModel.Annotations in the libraries section of project.assets.json, I see:
"System.ComponentModel.Annotations/4.5.0": {
"sha512": "UxYQ3FGUOtzJ7LfSdnYSFd7+oEv6M8NgUatatIN2HxNtDdlcvFAf+VIq4Of9cDMJEJC0aSRv/x898RYhB4Yppg==",
"type": "package",
"path": "system.componentmodel.annotations/4.5.0",
"files": [
// list of every file in package
]
},
see the path says system.componentmodel.annotations/4.5.0, which means it could be in either or both of c:\git\test\globalPackages\system.componentmodel.annotations\4.5.0 and/or C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.componentmodel.annotations\4.5.0.
For your use-case of trying to load it in Powershell, you can try to load one of the assemblies in the lib\* directory. Pick a TFM you think is compatible with your version of Powershell.
As for the reason that Solution Explorer doesn't have a twisty to expand the package, go find the package in the targets section of the project.assets.json and you'll see this:
"System.ComponentModel.Annotations/4.5.0": {
"type": "package",
"compile": {
"ref/netcoreapp2.0/_._": {}
},
"runtime": {
"lib/netcoreapp2.0/_._": {}
}
},
In other words, the package is not bringing in any assets or additional NuGet dependencies. Therefore nothing to expand in Solution Explorer.
In this specific case it's because netcoreapp2.0 has the assembly built-in to the runtime, and the Microsoft.NETCore.App package has the compile-time metadata for it. This is why I asked why you are looking for the package. If you use project.assets.json to find the exact System.ComponentModel.Annotations.dll that the build uses during compile, you'll find a metadata-only reference assembly that can't be loaded. But I gave insturations above on how to find the package directory and you can look for a loadable dll in one of the lib\* directories to try to load in Powershell.
Related
I am getting this error when I use the -LockMode switch with the nuget restore command.
NU1004: The packages lock file is inconsistent with the project
dependencies so restore can't be run in locked mode. Disable the
RestoreLockedMode MSBuild property or pass an explicit
--force-evaluate option to run restore to update the lock file.
What I am trying to achieve is to automatically upgrade my nuget references by using wildcards but use specific versions when I want to re-build my project from known sources. this blog posts describes how this can be achieved Enable repeatable package restores using a lock file.
When I use -UseLockFile & -LockMode on a simple solution with just one project it works as expected, the issue arises when I start adding another project to the solution.
Here're the steps:
I have published my package to an Azure DevOps feed and I have the following versions listed:
1.0.1-ci.1
1.0.1-ci.2
I have created a .Net 3.1 console app that references my package using wild cards, i.e. <PackageReference Include="My.Package" Version="1.0.*-ci.*" />
Running the command nuget restore -UseLockFile -ForceEvaluate creates the packages.lock.json with the right reference (I am using -ForceEvaluate in order to ensure it always resolves to the latest version available on the feed), the contents of the lock file of my console project are:
{
"version": 1,
"dependencies": {
".NETCoreApp,Version=v3.1": {
"My.Package": {
"type": "Direct",
"requested": "[1.0.*-ci.*, )",
"resolved": "1.0.0-ci.2",
"contentHash": "4HQuN7LNoZT9Z+MOL/Yig79FehhXBZmi26j3VtWR9Cgz8k5irWspSQ8aasVbNkYp7AgA2XaDQdr/cnwJnPilpQ=="
}
}
}
}
I then publish a new version of My.Package (1.0.1-ci.3) and run the command nuget restore -LockedMode, and the version resolved is still 1.0.1-ci.2, and if I then run nuget restore -ForceEvaluate it will resolve as expected to 1.0.1-ci.3, so far so good!
The issue arises when I add a class library to my solution which uses the same package reference, i.e. <PackageReference Include="My.Package" Version="1.0.*-ci.*" />, when I run restore -UseLockFile -ForceEvaluate my packages.lock.json file is updated to include the project dependency:
{
"version": 1,
"dependencies": {
".NETCoreApp,Version=v3.1": {
"My.Package": {
"type": "Direct",
"requested": "[1.0.*-ci.*, )",
"resolved": "1.0.0-ci.3",
"contentHash": "4HQuN7LNoZT9Z+MOL/Yig79FehhXBZmi26j3VtWR9Cgz8k5irWspSQ8aasVbNkYp7AgA2XaDQdr/cnwJnPilpQ=="
},
"classlibrary1": {
"type": "Project",
"dependencies": {
"My.Package": "1.0.0-ci.0"
}
}
}
}
}
While the contents of the lock file of the Class Library project are:
{
"version": 1,
"dependencies": {
".NETCoreApp,Version=v3.1": {
"My.Package": {
"type": "Direct",
"requested": "[1.0.*-ci.*, )",
"resolved": "1.0.0-ci.3",
"contentHash": "4HQuN7LNoZT9Z+MOL/Yig79FehhXBZmi26j3VtWR9Cgz8k5irWspSQ8aasVbNkYp7AgA2XaDQdr/cnwJnPilpQ=="
}
}
}
}
After this when I try running restore -LockMode I get the NU1004 error mentioned earlier.
Doing what the error message suggests and use -ForceEvaluate would clearly break what I wanted to achieve, yet I can't imagine that this relatively simple scenario is not covered by NuGet, so I would guess I am doing something wrong, does anyone have any ideas of what I could try to make this work?
It sounds like you're adding a new dependency then running nuget restore -LockedMode without first running nuget restore -ForceEvaluate.
It's not obvious what NuGet should do in that case - you're telling it you only want to use the dependencies in your lock file but you've also added new dependencies too.
It sounds like this would typically fail the restore:
If locked mode is set, restore will either get the exact packages as listed in the lock file or fail if it cannot. For example, if you updated the defined package dependencies for the project after lock file was created
https://devblogs.microsoft.com/nuget/enable-repeatable-package-restores-using-a-lock-file/#why-use-a-lock-file
You might have hit a corner case if the only transitive dependency of your new dependency is one that's already in the lock file but at a different version.
In general though, whenever you add new dependencies you're going to need to update your lock file, then after that you should be set to carry on running nuget restore -LockedMode.
I'm busy deploying a .NET Core 2.1 application into our testing environment, but I'm getting the following error.
Error:
An assembly specified in the application dependencies manifest (MyApp.deps.json) was not found:
package: 'System.Diagnostics.EventLog', version: '4.5.0'
path: 'runtimes/win/lib/netcoreapp2.1/System.Diagnostics.EventLog.dll'
We are using the Windows Compatibility Pack to access the Event Log.
I have the following item in the dependency Json file:
"System.Diagnostics.EventLog/4.5.0": {
"dependencies": {
"Microsoft.Win32.Registry": "4.5.0",
"System.Security.Permissions": "4.5.0",
"System.Security.Principal.Windows": "4.5.0",
"System.Threading.AccessControl": "4.5.0"
},
"runtime": {
"lib/netstandard2.0/System.Diagnostics.EventLog.dll": {
"assemblyVersion": "4.0.0.0",
"fileVersion": "4.6.26515.6"
}
},
"runtimeTargets": {
"runtimes/win/lib/netcoreapp2.0/System.Diagnostics.EventLog.dll": {
"rid": "win",
"assetType": "runtime",
"assemblyVersion": "4.0.0.0",
"fileVersion": "4.6.26515.6"
}
}
}
Please advise how one should deploy these dependencies. Also, what is the root folder to this relative path runtimes/win/lib/netcoreapp2.0?
We actually found a solution for our scenario:
- Our situation was that we tried to run a netcoreapp based test project on our test agent
- dotnet test on the project file worked
- dotnet vstest sometimes worked on the project output directory (we are not sure why and on which setup)
- dotnet vstest did run into the above error when run into an other directory & downloaded from CI
- dotnet vstest did run into an AssemblyNotFoundException on the test agent (which didn't make any sense for us)
The solution was to use dotnet publish for our test project and use the "self-contained" output to run on the test agent. dotnet publish copied the required runtimes/win/lib/netcoreappX.X/*.dll files into the publish output directory.
After a lot of testing, the key issue seems to be the "RuntimeIdentifiers". There is a visible option for this when you publish, but in order to use it when just building you need to add a couple of tags to your .csproj file.
The first is:
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
This will cause NuGet to retrieve the correct dlls (change the value depending on your needs). For me I was compiling to platform x86. I don't know what NuGet was getting by default, but whatever it was had different file sizes for the same files.
You also should then add this tag:
<SelfContained>false</SelfContained>
or else your build will default to copying the entire framework.
Also note that using the RuntimeIdentifier tag will cause your default output folder to include the value you specified. For example my subfolder became:
Project\bin\x86\Debug\netcoreapp3.1\win-86\
For publishing you should be able to do something similar; the problem will be to match your RuntimeIdentifier to your platform. You shouldn't need to specify SelfContained unless you specifically need to.
So i got roslyn built on my Mac OSX in a folder
dotnet/roslyn/Binaries/Debug/csccore
Here is the list of files I get
CommonNetCoreReferences_DoNotUse.dll*
CommonNetCoreReferences_DoNotUse.pdb*
Microsoft.CodeAnalysis.CSharp.dll*
Microsoft.CodeAnalysis.CSharp.pdb*
Microsoft.CodeAnalysis.CSharp.xml*
Microsoft.CodeAnalysis.dll*
Microsoft.CodeAnalysis.pdb*
Microsoft.CodeAnalysis.xml*
Microsoft.DiaSymReader.Native.amd64.dll*
Microsoft.DiaSymReader.Native.x86.dll*
Microsoft.Win32.Primitives.dll*
Microsoft.Win32.Registry.dll*
System.AppContext.dll*
System.Collections.Concurrent.dll*
System.Collections.Immutable.dll*
System.Collections.dll*
System.ComponentModel.DataAnnotations.dll*
System.Console.dll*
System.Core.dll*
System.Diagnostics.Debug.dll*
System.Diagnostics.FileVersionInfo.dll*
System.Diagnostics.Process.dll*
System.Diagnostics.StackTrace.dll*
System.Diagnostics.Tools.dll*
System.Diagnostics.Tracing.dll*
System.Dynamic.Runtime.dll*
System.Globalization.Calendars.dll*
System.Globalization.Native.dylib*
System.Globalization.dll*
System.IO.Compression.Native.dylib*
System.IO.Compression.dll*
System.IO.FileSystem.Primitives.dll*
System.IO.FileSystem.Watcher.dll*
System.IO.FileSystem.dll*
System.IO.Pipes.dll*
System.IO.dll*
System.Linq.Expressions.dll*
System.Linq.dll*
System.Native.a*
System.Native.dylib*
System.Net.Http.Native.dylib*
System.Net.NameResolution.dll*
System.Net.Primitives.dll*
System.Net.Sockets.dll*
System.Net.dll*
System.Numerics.dll*
System.ObjectModel.dll*
System.Private.CoreLib.dll*
System.Private.CoreLib.ni.dll*
System.Private.Uri.dll*
System.Reflection.Emit.ILGeneration.dll*
System.Reflection.Emit.Lightweight.dll*
System.Reflection.Emit.dll*
System.Reflection.Extensions.dll*
System.Reflection.Metadata.dll*
System.Reflection.Primitives.dll*
System.Reflection.TypeExtensions.dll*
System.Reflection.dll*
System.Resources.ResourceManager.dll*
System.Runtime.Extensions.dll*
System.Runtime.Handles.dll*
System.Runtime.InteropServices.RuntimeInformation.dll*
System.Runtime.InteropServices.dll*
System.Runtime.Loader.dll*
System.Runtime.Numerics.dll*
System.Runtime.Serialization.dll*
System.Runtime.dll*
System.Security.Claims.dll*
System.Security.Cryptography.Algorithms.dll*
System.Security.Cryptography.Cng.dll*
System.Security.Cryptography.Csp.dll*
System.Security.Cryptography.Encoding.dll*
System.Security.Cryptography.Native.dylib*
System.Security.Cryptography.OpenSsl.dll*
System.Security.Cryptography.Primitives.dll*
System.Security.Cryptography.X509Certificates.dll*
System.Security.Principal.Windows.dll*
System.Security.Principal.dll*
System.ServiceModel.Web.dll*
System.ServiceModel.dll*
System.Text.Encoding.CodePages.dll*
System.Text.Encoding.Extensions.dll*
System.Text.Encoding.dll*
System.Text.RegularExpressions.dll*
System.Threading.Overlapped.dll*
System.Threading.Tasks.Extensions.dll*
System.Threading.Tasks.Parallel.dll*
System.Threading.Tasks.dll*
System.Threading.Thread.dll*
System.Threading.ThreadPool.dll*
System.Threading.dll*
System.Windows.dll*
System.Xml.Linq.dll*
System.Xml.ReaderWriter.dll*
System.Xml.Serialization.dll*
System.Xml.XDocument.dll*
System.Xml.XPath.XDocument.dll*
System.Xml.XPath.dll*
System.Xml.XmlDocument.dll*
System.Xml.dll*
System.dll*
corerun*
csc*
csc.cmd
csc.exe*
csc.exe.config*
csc.pdb*
csc.xml*
libclrjit.dylib*
libcoreclr.dylib*
libdbgshim.dylib*
libmscordaccore.dylib*
libmscordbi.dylib*
libsos.dylib*
mscorlib.dll*
mscorlib.ni.dll*
pbcopy
sosdocsunix.txt*
Now how do i get it using in Visual Studio Code?
How do i refer local DLLs?
.Net Core projects can reference dependencies in two ways:
NuGet packages
project-to-project references
Notably, directly referencing assemblies is missing.
This means you have two options:
Build Roslyn NuGet packages, put them into a directory and configure that directory as a package source using NuGet.Config for your .Net Core project. Then reference the packages normally.
Make the relevant Roslyn projects part of your solution using global.json and then reference them as projects using "target": "project" instead of specifying a version of the package in project.json.
Every time I try either install or restore any package for my VS 15 / .net 5 / EF7 project I receive this error regardless of the package. I have been looking and cannot seem to find anything for this error with nuget specifically. If anyone could help me understand what is going on here would be appercaited.
Restore failed
A circular reference to 'EntityFramework.MicrosoftSqlServer.Design' was detected.
NuGet Config files used:
C:\Users\User\AppData\Roaming\NuGet\nuget.config
Feeds used:
https://api.nuget.org/v3-flatcontainer/
C:\Program Files (x86)\Microsoft Web Tools\DNU
In case anyone else has this problem when updating your project the problem was in the global.json file.
{
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-rc1-final"
}
}
my problem was the sdk version never updated when I switched from beta-8 to rc1-final. So just change that and you should be ok.
I have a portable class library project that targets .NET 4.6 and Universal Windows Platform. This class library contains just one class with the following line of code in its constructor:
Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));
Now I create a new .NET 4.6 console application project in the same solution and add a project reference to the portable class library. Calling the method that houses the above line of code results in the following exception at runtime:
Could not load file or assembly 'System.IO.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
What am I doing wrong here? There are no compile-time errors or warnings.
Things I have tried: add missing(?) NuGet package manually
It seems that System.IO.FileSystem is a library delivered via NuGet, as part of the Microsoft.NETCore mega-package. Okay, perhaps I need to explicitly add this package to any project that uses my portable class library. I attempt to do so.
Could not install package 'Microsoft.NETCore.Platforms 1.0.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
No luck with this approach.
Things I have tried: create a project.json file
While there is no clear info on the web, I read a few tidbits about a new project.json based NuGet harness or build system. Just to experiment, I created the following project.json file in my console application project:
{
"dependencies": {
},
"frameworks": {
"net46": { }
},
"runtimes": {
"win-anycpu": { }
}
}
It works! The runtime error goes away! However, I soon found that this was either not the right solution or not a complete solution. I started writing some code to read configuration section values, which involved making use of the IConfigurationSectionHandler interface, and got the following compile-time error:
error CS0246: The type or namespace name 'IConfigurationSectionHandler' could not be found (are you missing a using directive or an assembly reference?)
This interface is part of the System assembly. I see a reference to this assembly, but it has a yellow exclamation mark icon, and a warning appears in the warnings window:
The referenced component 'System' could not be found.
This is where I ran out of ideas. Am I missing something totally obvious?
I have found the solution. My initial attempt was to install the Microsoft.NETCore package into the console application, resulting in the error shown in my original post.
However, if I install only the narrowly-scoped packages, e.g. System.IO.FileSystem, then I achieve success and the application works correctly. Apparently there is something special about the Microsoft.NETCore "master package" that prevents it from correctly installing into dependent projects.