Error while trying to scaffold a model Visual Studio for Mac - visual-studio-mac

I'm using Visual Studio for MAC version 7.3.2 (build 12) and I'm trying to follow this tutorial from microsoft: https://learn.microsoft.com/en-us/aspnet/core/tutorials/razor-pages-mac/model
I have followed every step but I'm getting this error: Version for package Microsoft.VisualStudio.Web.CodeGeneration.Tools could not be resolve
My csproj file contain the following lines:
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.1" />
<DotNetCliToolReference Include="BundlerMinifier.Core" Version="2.5.357" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.1" />

Maybe your mac does not have this package installed? Try to install this package.
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Tools --version 2.0.4

Related

Run `dotnet test` equivalent with pure Mono

I'm trying F# and have a tiny project where I could run dotnet test, but I wanted to do it without installing any non-free software from Microsoft.
Alternatives to using dotnet all seem to use pretty complex commands like:
$ mono packages/xunit.runner.console.2.0.0/tools/xunit.console.exe build/test/CommandLine.Tests.dll
Being a complete newcomer, I have zero hint how those might need tweaking to work in my case.
My HelloWorld.fsproj contains:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<Compile Include="HelloWorld.fs" />
<Compile Include="HelloWorldTests.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
<PackageReference Include="FsUnit.xUnit" Version="4.0.2" />
</ItemGroup>
</Project>
Both Mono and .NET core have an MIT license. There's no reason you should not use .NET core nowadays, specially with .NET core 5 which is aiming at unifying the capabilities of .NET core and Mono.
On another note, there's an unnecessary line in your project code if you're not using Visual Studio (commercial license).
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />

Not able to build F# project in Azure Pipeline

I have an f# project in dotnet core 2.2 with following dependencies.
<PackageReference Include="Expecto" Version="8.12.0" />
<PackageReference Include="FSharp.Data" Version="3.3.2" />
<PackageReference Include="FSharp.Data.SqlClient" Version="2.0.5" />
I can build and run this locally without any problem.
But when trying to build this on azure pipeline I get the following error.
error FS3033: The type provider 'FSharp.Data.SqlCommandProvider' reported an error: Could not load file or assembly 'System.Data.SqlClient, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context.
I tryed adding System.Data.SqlClient packages. But still not working.
<PackageReference Include="Expecto" Version="8.12.0" />
<PackageReference Include="FSharp.Data" Version="3.3.3" />
<PackageReference Include="FSharp.Data.SqlClient" Version="2.0.6" />
<PackageReference Include="SQLProvider" Version="1.1.26" />
<PackageReference Include="System.Data.SqlClient" Version="4.5.1" />
When I try to add System.Data.SqlClient Version="4.4.0" i get following error locally
Detected package downgrade: System.Data.SqlClient from 4.5.1 to 4.4.0. Reference the package directly from the project to select a different version.
ElbBazarApiComponentTest -> FSharp.Data.SqlClient 2.0.6 -> System.Data.SqlClient (>= 4.5.1)
ElbBazarApiComponentTest -> System.Data.SqlClient (>= 4.4.0) ElbBazarApiComponentTest F:\ElbBazar\ElbBazarApi\ElbBazarApiComponentTest\ElbBazarApiComponentTest.fsproj
I do not know what else to do.
Not able to build F# project in Azure Pipeline
According to the error message:
Could not load file or assembly. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context.
It state that Could not load file or assembly rather than Could not found file or assembly.
Besides, when we check the nuget package FSharp.Data.SqlClient, which have dependencies:
So, the reason for that error is not that we have lost references System.Data.SqlClient, just we could not load it.
AFAIK, there is issue on the github about it, you could check if the workaround work for you, use MSBuild instead of dotnet build to build this project.
Hope this helps.

VS2019 Test Explorer not running tests for netcoreapp3.1 project using specflow+runner

Example repo here - https://github.com/venkatrao-rgare/specflow-vs2019/
After I do clean and build the test are generated in test explorer, when I try to right click on the test and run, it fails.
I looked at the "TestResults" folder to see this in the log, I don't have dotnet.exein C:\Program Files (x86)\dotnet\, not sure where to find it.
Can someone help with this? What should I install / configure to make this test run as expected ?
2020-02-04T12:34:26.0176209-06:00:System.ComponentModel.Win32Exception (2): The system cannot find the file specified.
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at TechTalk.SpecRun.Framework.Execution.OutOfProc.OutProcExecutorManager.StartProcess(ExecutorProcessInfo executorProcessInfo)
at TechTalk.SpecRun.VisualStudio.TestAdapter.VsOutProcExecutorManager.StartProcess(ExecutorProcessInfo executorProcessInfo)```
Stefan Zivkovic - It turned out to be an issue with Processor architecture. I posted this as a bug with Specflow not knowing if it was related to VS2019 or Specflow - the fix suggested in the comment in the bug to change the Processor architecture fixed it for me locally. - https://github.com/SpecFlowOSS/SpecFlow/issues/1877
You have this references in your project:
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="SpecFlow" Version="3.1.82" />
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.1.82" />
<PackageReference Include="SpecRun.Runner" Version="3.1.48" />
<PackageReference Include="SpecRun.SpecFlow" Version="3.1.48" />
</ItemGroup>
Please do remove references for Microsoft.NET.Test.Sdk and Newtonsoft.Json, and then run test.

F# core .NET framework on Linux build how-to

I'm trying to build a F# project (console) on Ubuntu 17.10 (Mono 4.6.2) however I run into F# core .NET issues. For reference, I'm using Visual Studio Code 1.21.2 and ionide extensions (new project and FAKE build). Below is the output.
I've tried adding an explicit reference to different versions of Fsharp.core e.g. 4.2, 4.3.4 with no luck.
Where should I be looking at to sort this out?
Finished Target: InstallDotNetCLI
Starting Target: Restore (==> InstallDotNetCLI)
/home/lear/.local/share/dotnetcore/dotnet restore
Restoring packages for /home/lear/src/fsTest/fsTest/fsTest.fsproj...
/home/lear/src/fsTest/fsTest/fsTest.fsproj : error NU1100: Unable to resolve 'FSharp.Core (>= 4.3.4)' for '.NETFramework,Version=v4.6.1'.
Restore failed in 99.61 ms for /home/lear/src/fsTest/fsTest/fsTest.fsproj.
Running build failed.
<ItemGroup>
<PackageReference Update="FSharp.Core" Version="4.3.4" />
</ItemGroup>
The project file looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="fsTest.fsproj">
<Name>fsTest.fsproj</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="fsTest.fs" />
<None Include="App.config" />
</ItemGroup>
<Import Project="..\.paket\Paket.Restore.targets" />
</Project>
I used this instructions as reference for my setup:
Four easy steps for installing F# on Ubuntu Linux (2017-07-03)
The project file specifies the wrong TargetFramework. Changing that to e.g. netcoreapp2.0 Target Framework Moniker should fix the build.
The project you are trying to build/restore is referencing itself. Just remove this portion from the fsproj file:
<ItemGroup>
<ProjectReference Include="fsTest.fsproj">
<Name>fsTest.fsproj</Name>
</ProjectReference>
</ItemGroup>

Namespace not defined in F# ASP.NET MVC project in VS Code

I'm currently trying to make some progress in learning F# and web development, and to that end I've used Yeoman to generate a F# ASP.NET project to start with (generator).
I've used Bower to install the dependencies, and the project both builds and runs with no issues, in both VS Code and just using dotnet run. However, navigating to the Startup.fs, it claims these namespaces opened aren't defined:
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.Extensions.Configuration
open Microsoft.Extensions.DependencyInjection
open Microsoft.Extensions.Logging
In the .fsproj file, the following packages are included, and I have run dotnet restore:
<PackageReference Include="FSharp.NET.Sdk" Version="1.0.0-beta-*" PrivateAssets="All"/>
<PackageReference Include="Microsoft.AspNetCore" Version="1.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.3"/>
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.0.2"/>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.0.2"/>
<PackageReference Include="Microsoft.FSharp.Core.netcore" Version="1.0.0-alpha-161023"/>
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.0.1"/>
To my mind, those lines should include at least some of the relevant NuGet packages for the namespace above. I would like to know how to let VS Code see that these namespaces are defined in the packages, and what's currently wrong. Any insight would be appreciated.
Per comments under the question moving my comment to the answer:
I haven't used F# with core however I noticed that you have a reference
<PackageReference Include="FSharp.NET.Sdk" Version="1.0.0-beta-*" PrivateAssets="All"/>
<PackageReference Include="Microsoft.FSharp.Core.netcore" Version="1.0.0-alpha-161023"/>.
I have a .net core 2 preview installed and generating new web project via dotnet command generated reference to
<PackageReference Include="FSharp.Core" Version="4.1.*" />
<PackageReference Include="FSharp.NET.Sdk" Version="1.0.*" PrivateAssets="All" />
which has not issues in VS Code

Resources