How to install FSharp.xUnit? - f#

I've installed Visual Studio 2017 and included the test package and the F# package. I'm trying to run a simple test using xUnit but it says xUnit is not found.
module HelloWorldTest
open FsUnit.xUnit
open Xunit
open System.Diagnostics
[<Fact>]
let ``Say Hello`` () =
Assert.True(true)
Error
The namespace or module 'FsUnit' is not defined.
I tried installing the package with dotnet but that produces an error.
> dotnet add package FSharp.xUnit
Writing C:\Temp\tmp8DAB.tmp
info : Adding PackageReference for package 'FSharp.xUnit' into project 'C:\Users\mjohn\workspace\fsharp\hello-world\HelloWorld.fsproj'.
log : Restoring packages for C:\Users\mjohn\workspace\fsharp\hello-world\HelloWorld.fsproj
...
error: Unable to find package FSharp.Core. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages
error: Unable to find package FsUnit.xUnit. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages
error: Unable to find package xunit. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages
error: Unable to find package xunit.runner.visualstudio. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages
error: Unable to find package FSharp.xUnit. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages
error: Unable to find package Microsoft.NET.Test.Sdk with version (>= 16.0.0)
error: - Found 1 version(s) in Microsoft Visual Studio Offline Packages [ Nearest version: 15.9.0]
error: Package 'FSharp.xUnit' is incompatible with 'all' frameworks in project 'C:\Users\mjohn\workspace\fsharp\hello-world\HelloWorld.fsproj'.
So how can I install xUnit for F#? This guide from MS unfortunately is lacking any of this information.
https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-fsharp-with-dotnet-test
EDIT:
After adding the NuGet package source
> dotnet add package FsUnit.xUnit
Writing C:\Temp\tmp5BA6.tmp
info : Adding PackageReference for package 'FsUnit.xUnit' into project 'C:\Users\mjohn\workspace\fsharp\hello-world\HelloWorld.fsproj'.
log : Restoring packages for C:\Users\mjohn\workspace\fsharp\hello-world\HelloWorld.fsproj
...
info : CACHE https://api.nuget.org/v3-flatcontainer/fsunit.xunit/index.json
info : Package 'FsUnit.xUnit' is compatible with all the specified frameworks in project 'C:\Users\mjohn\workspace\fsharp\hello-world\HelloWorld.fsproj'.
info : PackageReference for package 'FsUnit.xUnit' version '3.4.0' updated in file 'C:\Users\mjohn\workspace\fsharp\hello-world\HelloWorld.fsproj'.

Related

How to fix error loading DiagnosticAnalyzerFieldsAnalyzer

Visual Studio 2022 was installed on clean Windows 11 using Web Development profile.
Running existing ASP.NET 6 MVC project in it using F5 throws error in build window
NuGet package restore failed. Please see Error List window for detailed warnings and errors.
Error occurred while restoring NuGet packages: The operation failed as details for project MyApp could not be loaded.
Error window contains number of warnings
> Severity Code Description Project File Line Suppression State
> Warning CS8032 An instance of analyzer Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpDiagnosticAnalyzerFieldsAnalyzer
> cannot be created from
> C:\Users\kobru\.nuget\packages\microsoft.codeanalysis.analyzers\3.0.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll: Could not load type
> 'Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.DiagnosticAnalyzerFieldsAnalyzer`4'
> from assembly 'Microsoft.CodeAnalysis.Analyzers, Version=3.3.3.10305,
> Culture=neutral, PublicKeyToken=31bf3856ad364e35'..
Will this stop code analyzer? How to fix this so that warnings to not appear?
Usually the NuGet package restore failed... error means that the required package doesn't exist in the NuGet global-packages folder or the package installation is corrupted.
The simplest way to resolve this problem is to install/reinstall the package by using the NuGet Package Manager or perform the following command from the Package Manager console in the Visual Studio:
Install-Package package_name
An additional information:
Install and manage packages in Visual Studio using the NuGet Package Manager
Manage packages with the Visual Studio Package Manager Console (PowerShell)

lib.web.mvc installation issue with VS 2017

I am getting the following error while installing the lib.web.mvc.6.8.2 package with VS 2017. It seems there is an issue with the dependency Microsoft.AspNet.Mvc already installed:
PM> Install-Package Microsoft.AspNet.Mvc
Package 'Microsoft.AspNet.Mvc.5.2.3' already exists in project 'MyMVCApplication' Time Elapsed: 00:00:00.6708551
PM> Install-Package Lib.Web.Mvc -Version 6.8.2
Attempting to gather dependency information for package
'Lib.Web.Mvc.6.8.2' with respect to project 'MyMVCApplication',
targeting '.NETFramework,Version=v4.5.2'
Gathering dependency information took 8,86 sec
Attempting to resolve dependencies for package 'Lib.Web.Mvc.6.8.2'
with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'Lib.Web.Mvc.6.8.2'
Resolved actions to install package 'Lib.Web.Mvc.6.8.2'
Retrieving package 'Lib.Web.Mvc 6.8.2' from 'nuget.org'. Install
failed. Rolling back...
Package 'Lib.Web.Mvc.6.8.2 : Microsoft.AspNet.Mvc [4.0.0, 6.0.0)' does not exist in project 'MyMVCApplication'
Package 'Lib.Web.Mvc.6.8.2 : Microsoft.AspNet.Mvc [4.0.0, 6.0.0)' does
not exist in folder 'C:\Users\Cyberphil83\documents\visual studio
2017\Projects\MyMVCApplication\packages'
Executing nuget actions took 19,84 ms Install-Package : Could not
install package 'Lib.Web.Mvc 6.8.2'. You are trying to install this
package into a project that targets '.NETFramework,Version=v4.5.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.At line:1 char:1
+ Install-Package Lib.Web.Mvc -Version 6.8.2
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
I checked the github of this project, and it looks like it is targeting .NET 4.6:
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
Lib.Web.Mvc.csproj
But your app is targeting 4.5.2.
So you have few options. One of them is to clone/fork this project and compile targeting 4.5.2. Or simply change your app to 4.6 (if possible?).
Since v6.8.0 release Lib.Web.Mvc requires .NET 4.6+ as it requires HTTP/2 support.
There is a v6.7.x branch which is fix-only branch supporting .NET 4.0+.
If you want to stick to .NET 4.5.2 you will have to use latest 6.7.x version:
PM> Install-Package Lib.Web.Mvc -Version 6.7.1
Alternative is to upgrade your project to .NET 4.6+.

TFS unable to restore nuget packages (dev PCs build ok)

A previously working on-premises TFS 2015 (with update 1) fails all builds that have nuget packages in them. The build log shows:
MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
Restoring NuGet package StyleCop.Error.MSBuild.1.0.0.
Restoring NuGet package Microsoft.Diagnostics.Tracing.EventSource.Redist.1.1.28.
Restoring NuGet package Microsoft.Diagnostics.Tracing.EventRegister.1.1.28.
Restoring NuGet package Microsoft.Diagnostics.Tracing.EventSource.1.1.28.
Restoring NuGet package StyleCop.MSBuild.4.7.50.
Restoring NuGet package Newtonsoft.Json.8.0.3.
Restoring NuGet package Dapper.1.42.0.
Restoring NuGet package FluentAssertions.4.2.2.
WARNUNG: Unable to find version '1.1.28' of package 'Microsoft.Diagnostics.Tracing.EventRegister'.
WARNUNG: Unable to find version '1.0.0' of package 'StyleCop.Error.MSBuild'.
WARNUNG: Unable to find version '1.1.28' of package 'Microsoft.Diagnostics.Tracing.EventSource.Redist'.
WARNUNG: Unable to find version '1.1.28' of package 'Microsoft.Diagnostics.Tracing.EventSource'.
WARNUNG: Unable to find version '1.42.0' of package 'Dapper'.
WARNUNG: Unable to find version '8.0.3' of package 'Newtonsoft.Json'.
WARNUNG: Unable to find version '4.7.50' of package 'StyleCop.MSBuild'.
WARNUNG: Unable to find version '4.2.2' of package 'FluentAssertions'.
Unable to find version '4.2.2' of package 'FluentAssertions'.
Unable to find version '4.7.50' of package 'StyleCop.MSBuild'.
Unable to find version '1.1.28' of package 'Microsoft.Diagnostics.Tracing.EventRegister'.
Unable to find version '8.0.3' of package 'Newtonsoft.Json'.
Unable to find version '1.42.0' of package 'Dapper'.
Unable to find version '1.1.28' of package 'Microsoft.Diagnostics.Tracing.EventSource'.
Unable to find version '1.1.28' of package 'Microsoft.Diagnostics.Tracing.EventSource.Redist'.
Unable to find version '1.0.0' of package 'StyleCop.Error.MSBuild'.
Unerwarteter Exitcode 1 vom Tool NuGet.exe zurückgegeben
On dev PCs the solutions build just fine and nuget packages are restored without problems.
How to fix this?
The error message indicates that the packages cannot be found in your package resource. Since the packages can be restored on you dev PC, you can compare the nuget.config file on your TFS server and dev PCs to see if there is any difference between them. The nuget.config file locates at "%APPDATA%\NuGet\NuGet.Config".
And the nuget.exe version you use may also cause this issue, see this question for reference: "Unable to find version" during TFS Build 2015 when restoring NuGet packages

Can not install SignalR client nuget package for MonoDroid

I was trying to install Nuget package for MonoDroid project (Visual Studio 2015):
Microsoft.AspNet.SignalR.Client
And I got this error:
Could not install package 'Microsoft.AspNet.SignalR.Client 2.2.0'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v4.3', but the package does not contain any assembly references or content files that are compatible with that framework.
Any idea to sort this out?

Can't install Websharper nuget

When i'm trying to create a sitelet project, nuget fails on installing
NuGet Package restore failed for project To2a1.PublicSite.WebSharper: Could not find file 'C:\Users\Michakun\AppData\Local\Temp\nuget\atxvmxdn.eba\tools\net40\IntelliFactory.WebSharper.Web.dll'
Anyone knows why? I'm using visual studio 2013 update 4

Resources