Refer to the screenshot below, I need to use DynamicObject in .net standard 1.6 library project.
However, I cannot add any additional dependencies by right click the Dependencies and Add Reference in Visual Studio 2017 Enterprise (15.2).
Does anyone know how to use DynamicObject in .net standard class library project targeting netstandard 1.6?
You need to add the System.Dynamic.Runtime NuGet package for the type to become available in the System.Dynamic namespace. In netstandard2.0, it will be available automatically.
dotnet add package System.Dynamic.Runtime
Related
I want to use log4net in my .net core 2.1 project but when I add it, it has a yellow exclamation triangle next to it and I get this message in the output window.
warning NU1701: Package 'log4net 2.0.5' was restored using
'.NETFramework,Version=v4.6.1' instead of the project target framework
'.NETCoreApp,Version=v2.1'. This package may not be fully compatible
with your project.
Any idea how I can make the project happy using log4net? what will happen if I try and use it with the exclamation?
Upgrade your Log4net to at least version 2.0.6 (or higher) as from this version it supports .NET Standard 1.3 which allows Log4net to be used on .NET Core.
Note that not everything is supported on .NET Core (eg. AdoNetAppender, SmtpAppender) see the release notes.
I was trying to create a common library for using HttpClient to consume an API. I was planning to make it in .net standard so as to share it with my xamarin.forms project right now and any future ones. However the highest version of .net standard I managed to use was 1.0. HttpClient needs standard2.0. I have included the latest version of .netstandard nuget into my xamarin.forms.
I have noticed that xamarin.forms runs in net4.5. According to the documentations the max I can go with this is standard1.1. Is there any work around around these to a .net standard common project or is my only option to make a .net framework project/xamarin portable library?
I used to be in the same situation and I managed to pull through this. First I tried to upgrade my current PCL project to .netStandard, but it was always failing, so I decided to create a new Project A Class Library (.NETStandard), moved all my files to the new project and re-install all nuget packages.
New project configuration:
Target Framwork: .NET Standard 2.0
Output type: Class Library
Make sure you're using Microsoft Visual Studio > version 15.3
Hope it helps.
I did manage to get HttpClient working in .net standard after manually importing the class. It needed an additional reference which is why it threw an error when I downgraded from .netcore.
This seems to work sometimes and throws reference errors other times. These errors go when I close and re-open visual studios.
I'm using default Roslyn SDK templates that came with Visual Studio 2017. The projects they create target .NET Framework Portable. I'm assuming Roslyn extensibility projects can target .NET Standard \ Core instead of Portable and I'm looking for templates or a sample of Roslyn Analyzer \ Refactoring project that I could study.
Sample of converted analyzer from default analyzer template is available here. There is original analyzer for comparison along with TestAnalyzerStandard which targets .NET standard.
Steps to make it work:
Create new .NET Standard library
Library must target .NET Standard 1.3. This is required if you wish to run analyzer as extension inside VS (extensions target .NET 4.6). Mapping between standard versions and full framework versions is available here. Also if you try to target lower version than 1.3, you will not be able to include required analyzer packages.
Add nuget package for Microsoft.Composition latest version. This is needed by Microsoft.CodeAnalysis.CSharp.Workspaces. If you try to add workspaces first, you will get error that referenced composition package is not compatible.
Add nuget package for Microsoft.CodeAnalysis.CSharp (I'm using latest 1.* version)
Add nuget package for Microsoft.CodeAnalysis.Csharp.Workspaces (version should match the version of Microsoft.CodeAnalysis.CSharp).
At this point you can copy code from portable project and build it. There should be no errors (you may have to close and reopen solution if VS is still displaying red squiggles).
To make VS extension work, just open source.extension.vsixmanifest, go to assets tab and change reference to .NET standard library
To create .nuget package just execute nuget pack Diagnostic.nuspec .. Diagnostic.nuspec is valid for Nuget 2.x. If you are using nuget via package management console in VS 2017 you will have to change <file src="*.dll" ..." to <file src="bin\*\netstandard1.3\*.dll" ....
Those steps are result of my experimentation with analyzers (I previously played with creating DLL which targeted full framework instead of being portable library). They are not by any means official.
I started working on a new Roslyn project and built things one by one instead of using template. https://github.com/IKoshelev/Roslyn.AutoLogging/commit/1f88e3e49141e0fa425c51fdcb3457a7c3d6dcaa
I managed to have the following targeting:
Refactoring project - .NET Standard 1.3 (this .dll will be distributed, version kept to minimum)
UnitTests project - .NET Core 2.0
VSIX project - .NET Framework 4.6 (I believe, only full Visual Studio supports VSIX, so that is okay)
Update Versioning of Roslyn is a bit more complicated right now, i.e. if you want to use your extensions with Visual Studio 2015 you will have to use PCL libraries. More info at the end of this article article on Roslyn
I'm trying to use the System.IdentityModel.Token.Jwt NuGet package for my Xamarin.Forms app. When I try to add the package to my PCL, it installs in my Android and iOS projects, but I get the following error when adding it to the shared code project:
Could not install package 'System.IdentityModel.Tokens.Jwt 5.1.3'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.6,Profile=Profile44', 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.
Does anyone know how to get around this? I think it has to do with what my project targets but I've tried a few combinations and all of them have produced the same error, just with a different profile listed.
Unfortunately the System.IdentityModel.Tokens.Jwt 5.1.3 NuGet package only contains assemblies that support:
.NET Framework 4.5.1
.NET Standard 1.4
No portable class library profile supports .NET Standard 1.4. The highest they support is .NET Standard 1.2.
So unless you can find another NuGet package that does support portable class libraries you are left with trying to compile the Jwt source code for the portable class library profile you need, or converting your portable class library project into a .NET Standard project and target at least 1.4. You should be able to convert your portable class library project into a .NET Standard project in the project options.
I am trying to install the nuget pacakge EntityFramwork.Sqlite in a portable library which targets are .net 4.6 and windows universal 10.0. If I do that, I get an error that says package restore failed.
If I create project library that is for .net 4.6 then I can add the package and if I create a universal portable library only for windows 10 applications, I can add the package too.
So, if I can use the package in .net 4.6 projects and windows universal projects, why can I not use it in a portable library that targets this kind of projects?
Thanks.
EF7 currently targets netstandard1.3 (aka dotnet5.4) and .NET 4.5.1. As of today (Jan 14, 2016), there is no PCL profile to includes both of these. (see http://embed.plnkr.co/03ck2dCtnJogBKHJ9EjY).
See also https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/standard-platform.md