Accessing local built DLL in Visual Studio Code project - visual-studio-code

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.

Related

Trying to install package into a project that targets '.NETFramework,Version=v4.7.2', but the package does not contain any assembly references

I used NuGet Package Explorer (for the first time) to create a .nupkg to share with others. I have one DLL that targets NetStandardLibrary 2.0,
But when I try to add the package I receive the following error:
Could not install package 'iCANMVCSDK 1.0.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.7.2', 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.
I thought that by using NETStandard 2.0 it could be installed in any .NET app. I also tried adding additional assemblies:
I rebuild, repackage, and I still get the same error. What am I missing?
I tried editing the project file like this:
<TargetFrameworks>netstandard2.0;net472</TargetFrameworks>
When I try to build after adding net472, I receive the following error:
The type or namespace name 'Http' does not exist in the namespace 'System.Net'
What really makes no sense to me is that I can add the DLL directly into the project (the one that targes NET 4.72) and it works as expected. The problem is when attempting to install it as a NuGet package.

Unable to find nuget folder

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.

How can I force dependent project to install nuget package used in dependency?

I developed a nuget package "nuget_X" installed on a project "project_1".
I have a second project "project_2" that reference "project_1".
If "project_1" is published as nuget package "nuget_1", I can force "project_2" to reference "nuget_X" by declaring "nuget_X" as dependency of "nuget_1"
But "project_1" is referenced as "ProjectReference". So, how can I configure "nuget_X" or "project_1" to force "project_2" to install "nuget_X"?
PackageReference on Visual Studio 2017 don't allow to force nuget of dependency to be installed when using ProjectReference. But it allow to produce an acceptable equivalent result. for more details, see comments.

Where to find documentation of all supported nuget framework names

When building a nuget package with folder lib\i-made-this-up\, nuget Pack will output the following message:
The folder 'i-made-this-up' under 'lib' is not recognized
as a valid framework name or a supported culture identifier.
Folder lib\net40-wpf\ does not output this message so apparently it is a valid framework name. My questions is: how is net40-wpf defined? I expected it to be on this page but it isn't:
https://docs.nuget.org/create/enforced-package-conventions
Do I miss something? Or is there a better source of documentation?
You have the main documentation link for the NuGet target frameworks:
https://docs.nuget.org/create/enforced-package-conventions
Unfortunately it is out of date and is missing newer target frameworks that NuGet supports.
A few more target frameworks are mentioned in the following blog post:
http://blog.nuget.org/20150729/Introducing-nuget-uwp.html
Currently the best place is the NuGet source code. For NuGet v2 the known target frameworks are defined in the VersionUtility class:
https://github.com/NuGet/NuGet2/blob/2.8.6/src/Core/Utility/VersionUtility.cs
For NuGet 3 the list of target frameworks is defined in the FrameworkConstants class:
https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.Frameworks/FrameworkConstants.cs
NuGet 3 also has a set of runtime identifiers which are defined in a NuGet package so it is extensible.

Type or Namespace "Dapper" could not be found: in Hangfire Source code in Visual Studios?

I've imported the Hangfire Source code from Github into my existing VS 2013 solution. When I attempted to build all projects within my solution, I get several errors:
Error 6 The type or namespace name 'Dapper' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Jerry_Dev\Documents\GitHub\Hangfire\src\Hangfire.SqlServer\SqlServerDistributedLock.cs 20 7 Hangfire.SqlServer
In Package Manager, when I do: "Install-Package Dapper", it says
'Dapper 1.38' already installed.
Hangfire.SqlServer already has a reference to 'Dapper 1.38'.
I see Dapper dot net installed in my Manage Nuget Packages Window in my Hangfire.SqlServer project
We don't store the packages folder under source control to reduce the source code size. Hangfire uses Automatic Package Restore in Visual Studio instead of obsolete MSBuild-integrated package restore. The Automatic Restore downloads missing packages automatically on each build, but it works only with NuGet ≥ 2.7, so you have the following options:
Update NuGet to the latest version
Please see the official docs.
Run the build script
Go to the root Hangfire directory and run the build.bat file. It will automatically restore all the missing packages.