I have used this config lots of times before and never had any problems so I stripped my project back to basics. I am using Specflow with Specrun and the specrun part is the only thing which has changed.
I am trying to configure a serilog logger using the appsettings.json file which is located in my.net core bin base directory.
\bin\Debug\netcoreapp3.1
Previously I could just reference the appsettings without a path without a basepath but this has changed when I moved from NUnit to Specflow. Still using basepath can still find the location. However when I attempt to create the logger and use readfrom it is referencing the appsettings file from a weird location and not the ConfigurationRoot in the configuration variable I just set.
Below are the two setup variables. The first for the configuration root of appsettings the second for the serilog logger. The first is successful and gives me what looks to be a valid IConfiguration object. The second is where the error occurs. This error being
"System.IO.FileNotFoundException: 'Could not find file '\bin\Debug\netcoreapp3.1\SpecFlowPlusRunner\netcoreapp3.1\TechTalk.SpecRun.Framework.Executor.anycpu.netcoreapp3_1.deps.json'.'"
var configuration = new ConfigurationBuilder()
.SetBasePath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))
.AddJsonFile("appsettings.json")
.Build();
var logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
Some additional information of note.
This is a netcore 3.1 app
The code is executed within a specflow class
packages included are.
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.6" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.6" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.6" />
<PackageReference Include="Serilog" Version="2.9.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.Seq" Version="4.0.0" />
<PackageReference Include="SpecFlow" Version="3.3.57" />
<PackageReference Include="SpecFlow.NetCore" Version="1.3.5" />
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.3.57" />
<PackageReference Include="SpecRun.SpecFlow" Version="3.3.41" />
I assume that your basepath for the configuration is wrong. Assembly.GetExecutingAssembly() is probably returning one of the SpecFlow+ Runner assemblies, which are contained in the SpecFlowPlusRunner subfolder.
To get the folder where your test assemblies are, we have an API for it: TestRunContext.TestDirectory (https://docs.specflow.org/projects/specflow-runner/en/latest/Usage/SpecFlow-Runner-APIs.html#string-testdirectory-get).
With that, you should get the correct folder where your appsettings.json is.
Full disclosure: I am one of the developers of SpecFlow and SpecFlow+.
Related
I have tried about twenty solutions I have found online on how to prevent appsettings.{somevalue}.json from being published with the wrong environment. Basically I have a "development" variant and "production" variant and both are set to Copy If Newer under properties in the project. I have 2 publish profiles publishing a Worker Service app to a remote directory, one for debug configuration to my development environment (where the DOTNET_ENVIRONMENT is set to Development) and one to a similar production environment. I want to exclude the opposite environments config file from the publish or build automatically. Simple solution is to delete the file myself, however I want to make sure this is automated when published. Part of the issue is the complete lack of information on what goes in these pubxml files or csproj file that allows you to remove or delete files. Other questions on stack exchange have noted this lack of information as well.
Here is what I have recently tried and I have tried placing these blocks in both pubxml files and csproj file both inside and outside of the PropertyGroup node but none of these work:
1.
<Target Name="Debug" AfterTargets="AfterPublish">
<Message Text="Development Publish Message"></Message>
<Delete Files="appsettings.Production.json" />
</Target>
(I have also tried specifying variables for that json file's location as well as hardcoding its actual path in the final publish. This does nothing and that message isn't shown anywhere)
2.
<ItemGroup>
<Content Remove="appsettings.Production.json" />
</ItemGroup>
<ExcludeFilesFromDeployment>
bin\Debug\netcoreapp3.1\appsettings.Production.json;
</ExcludeFilesFromDeployment>
<ItemGroup>
<Content Update="appsettings.Production.json" CopyToPublishDirectory="Never" />
</ItemGroup>
(this one is straight from Microsoft but like many others, does nothing)
https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/visual-studio-publish-profiles?view=aspnetcore-6.0
<Choose>
<When Condition="'$(Configuration)' == 'Debug'">
<ItemGroup>
<None Include="appsettings.Production.json" CopyToOutputDirectory="Never" CopyToPublishDirectory="Never" />
</ItemGroup>
</When>
<When Condition="'$(Configuration)' == 'Release'">
<ItemGroup>
<None Include="appsettings.Development.json" CopyToOutputDirectory="Never" CopyToPublishDirectory="Never" />
</ItemGroup>
</When>
</Choose>
I could continue but nothing I have found works. Is this even possible?
Thanks!
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.
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.
I'm building a multi-platform class library with Xamarin. The Android project builds with no problem. But the iOS project gives me a bunch of errors like this, for various System types:
error CS0012: The type 'System.IDisposable' is defined in an assembly that is not referenced. Consider adding a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
This happens regardless of whether I build via Visual Studio, or on the command line with msbuild.
My .csproj has these framework references and package references:
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http" />
<Reference Include="Xamarin.iOS" />
<PackageReference Include="Common.Logging" Version="3.4.1" />
<PackageReference Include="Xamarin.Essentials" Version="0.8.0-preview" />
<PackageReference Include="Xam.Plugin.DeviceInfo" Version="4.0.0.13" />
<PackageReference Include="My.Other.Library" Version="1.0.2" />
</ItemGroup>
Note that My.Other.Library is not an iOS project; it has targets of netstandard1.4, netstandard1.6, netstandard2.0, and net45. I'm guessing that that is not the problem, because the same library is also used by my Android project, which works fine.
Currently these two projects have the same code - that is, they both compile the same .cs files from a shared directory, except for AssemblyInfo.cs which exists separately in each project. They also have the same assembly references, except that the Android project uses Mono.Android rather than Xamarin.iOS.
I'm using Mac Visual Studio Community 7.5.2.
Any ideas?
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