Specflow test project fails build .NET 5 windows7 - visual-studio-2019

I get this error building my specflow test project
I cannot figure out why I get these compile bugs..
I am quite sure it has to do with use .NET 5,
don't have a lib folder, where the libraries/nugets are stored...
my project looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0-windows7.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="SpecFlow.Plus.LivingDocPlugin" Version="3.9.57" />
<PackageReference Include="SpecFlow.MsTest" Version="3.9.74" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="FluentAssertions" Version="6.7.0" />
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<OutputPath>..\Bin\Debug</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<OutputPath>..\Bin\Release</OutputPath>
</PropertyGroup>
<ItemGroup>
<Folder Include="Drivers\" />
<Folder Include="Hooks\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MagVenture.Utilities.UI\MagVenture.Utilities.UI.csproj" />
</ItemGroup>
I cannot figure it out... - there is a twirl somewhere that I didn't see..

Disable the NU5100 warning, when treating warnings as errors.
it is due to the .NET framework versions policies about location in lib folder.

Related

MsDeploySkipRules being ignored on project publish

I want to exclude ALL files & folders in wwwroot\data from being published to my website folder. The files in my website folder are the latest copy and should never be overwritten when I publish the project.
Reference Microsoft documentation
The documentation indicates using this xml in .csproj file but I can't get it to work. I've tried putting this in both my .csproj file and .pubxml with no success.
What am I doing wrong? Can someone tell me if this actually works?
<ItemGroup>
<MsDeploySkipRules Include="CustomSkipFolder">
<ObjectName>dirPath</ObjectName>
<AbsolutePath>wwwroot\\data</AbsolutePath>
</MsDeploySkipRules>
</ItemGroup>
Here is my .pubxml file:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<DeleteExistingFiles>False</DeleteExistingFiles>
<ExcludeApp_Data>False</ExcludeApp_Data>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>C:\www\VisualStudio2019-Core3</PublishUrl>
<WebPublishMethod>FileSystem</WebPublishMethod>
<SiteUrlToLaunchAfterPublish />
<TargetFramework>netcoreapp3.1</TargetFramework>
<ProjectGuid>881d6bfb-ed04-41d7-b600-0e26765ff90e</ProjectGuid>
<SelfContained>false</SelfContained>
</PropertyGroup>
Tried putting code here -->>
</Project>
Here is my .csproj file:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>VisualStudio2019_Core3</RootNamespace>
<UserSecretsId>93d2ec1f-4bcc-4aa5-ad65-4bdbdce5690a</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.3" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.1.5" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.2" />
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="2.19.60" />
</ItemGroup>
Tried putting code here -->>
</Project>
Additional information:
Visual Studio 2019
Web Application Core 3.1
Publishing via Studio menus...not command line.
I used this (referring to my webapp) after end tag PropertyGroup
<ItemGroup>
<Content Remove="appsettings.Development.*" />
<Content Remove="bundleconfig.json" />
<Content Remove="wwwroot\js\Site.js" />
<Content Remove="wwwroot\js\webcam-easy.js" />
<Content Remove="wwwroot\js\webcam-app.js" />
<Content Remove="wwwroot\css\Site.css" />
<Content Update="wwwroot\js\Site.js" CopyToPublishDirectory="Never" />
<Content Update="wwwroot\js\webcam-easy.js" CopyToPublishDirectory="Never" />
<Content Update="wwwroot\js\webcam-app.js" CopyToPublishDirectory="Never" />
<Content Update="wwwroot\css\Site.css" CopyToPublishDirectory="Never" />
<ResolvedFileToPublish Include="wwwroot\css\xxxxx.min.css">
<RelativePath>wwwroot\css\xxxxx.min.css</RelativePath>
</ResolvedFileToPublish>
<ResolvedFileToPublish Include="wwwroot\js\xxxxx.min.js">
<RelativePath>wwwroot\js\xxxxx.min.js</RelativePath>
</ResolvedFileToPublish>
<MsDeploySkipRules Include="connectionconfig">
<ObjectName>filePath</ObjectName>
<AbsolutePath>connection.json</AbsolutePath>
</MsDeploySkipRules>
</ItemGroup>

Microsoft.CodeAnalysis.BuildTasks.Csc" task could not be loaded from the assembly

I am trying to install an existing project in Dotnet core but I was getting the error
<PropertyGroup>
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
<StartupObject></StartupObject>
<!--<PreserveCompilationContext>true</PreserveCompilationContext>
<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>-->
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Boilerplate.AspNetCore" Version="3.0.0" />
<PackageReference Include="BuildBundlerMinifier" Version="2.8.391" />
<PackageReference Include="Captcha" Version="4.4.2" />
<PackageReference Include="linqtotwitter" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNet.Identity.Core" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="1.1.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="3.2.1" />
</ItemGroup>
Try to update these from the NuGet Package Manager will fix your issue
Microsoft.CodeDom.Providers.DotNetCompilerPlatform
Microsoft.Net.Compilers

MSBuild not adding a /reference for nuget PackageReference when building with jenkins

I have a jenkins build that cleans, restores, and then builds a unit test project. This project, along with my others, have recently been migrated to use PackageReference. The clean works, and the restore works. I verified that NUnit exists in %userprofile%/.nuget/packages/. Here are the commands that are in my build script:
msbuild /p:Configuration="Debug" /t:clean OtherProjectName.Test.csproj
msbuild /p:Configuration="Debug" /t:restore OtherProjectName.Test.csproj
msbuild /p:Configuration="Debug" OtherProjectName.Test.csproj
This later results in output that looks something like this:
csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /highentropyva+
/reference:<one of my references> /reference:<another one> /reference:<and so on>
/out:obj\Debug\OtherProjectName.Test.dll /subsystemversion:6.00 /target:library /utf8output <a list of source files>
The build for my project fails because it can't find NUnit (see below). I believe it can't find NUnit because the compilation command does not include a "/reference" to the NUnit nuget package.
error CS0246: The type or namespace name 'NUnit' could not be found (are you missing a using directive or an assembly reference?
My other projects do have '/reference' for NuGet packages. So I compared them to see if anything looked significantly different. I did notice that most of my projects include this line at the start:
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
I thought that might be the culprit, based on my brief reading on what this line does, but when I tried the same steps on my local machine (it has VS2017 and MSbuild 15, just like the jenkins server) I could not replicate the issue.
My .csproj file has the following:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{a guid}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OtherProjectName.Test</RootNamespace>
<AssemblyName>OtherProjectName.Test</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<!-- a couple entries like this -->
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net">
<HintPath>Z:\path\to\log4net.dll</HintPath>
</Reference>
<!-- a couple references like this -->
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise />
</Choose>
<ItemGroup>
<!-- all my C# source files -->
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OtherProjectName\OtherProjectName.csproj">
<Project>{a guid}</Project>
<Name>OtherProjectName</Name>
</ProjectReference>
<ProjectReference Include="..\OtherProjectName2\OtherProjectName2.csproj">
<Project>{another guid}</Project>
<Name>OtherProjectName2</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<None Include="App.config.1" />
<None Include="Unit Test Playlists\Fast.playlist" />
<!-- all my unit test playlists -->
</ItemGroup>
<ItemGroup>
<PackageReference Include="NUnit">
<Version>3.11.0</Version>
</PackageReference>
<PackageReference Include="NUnit.ConsoleRunner">
<Version>3.9.0</Version>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter">
<Version>3.11.0</Version>
</PackageReference>
<!-- other nuget packages -->
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Please compare the version of the MSBUILD on your local and the build server. Looks like you might have a lower version of MSBUILD running on the build server that doesn't support packagereferences.

Build project with multiple targetframeworks in TFS as a NuGet package

I want to build my NuGet package in one of my TFS build steps.
Because .NET Standard 2.0 is currently not supported by the TFS NuGet step, I am using /t:pack as the build argument in my MSBuild invocation.
When I only use one TargetFramework it is working fine. My assemblies get a version and my NuGet package too.
Even if I am using an AssemblyInfo.cs in .NET Standard 2.0 - explained in this answer.
So far no problem, but if I want to build now on two different TargetFrameworks like <TargetFramework>netstandard2.0;net45</TargetFramework> my NuGet package won't get a Version.
So in the end this is working and is generating a versioned NuGet file.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<GenerateNuspecDependsOn>$(GenerateNuspecDependsOn);ReadPackageVersionFromOutputAssembly</GenerateNuspecDependsOn>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<Target Name="ReadPackageVersionFromOutputAssembly" DependsOnTargets="Build">
<GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
<Output TaskParameter="Assemblies" ItemName="PackAssembly" />
</GetAssemblyIdentity>
<PropertyGroup>
<PackageVersion>%(PackAssembly.Version)</PackageVersion>
</PropertyGroup>
</Target>
<ItemGroup>
<Compile Remove="AccessControl\**" />
<EmbeddedResource Remove="AccessControl\**" />
<None Remove="AccessControl\**" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\common\Version.cs" Link="Properties\Version.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="4.8.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="MyEngine">
<HintPath>..\libs\NetStandard\MyEngine.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
</Project>
So here is my current .csproj file. This builds too and also generates a NuGet file. But in this case my NuGet file is unversioned. Why is it this way and how can I fix it?
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<GenerateNuspecDependsOn>$(GenerateNuspecDependsOn);ReadPackageVersionFromOutputAssembly</GenerateNuspecDependsOn>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<Target Name="ReadPackageVersionFromOutputAssembly" DependsOnTargets="Build">
<GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
<Output TaskParameter="Assemblies" ItemName="PackAssembly" />
</GetAssemblyIdentity>
<PropertyGroup>
<PackageVersion>%(PackAssembly.Version)</PackageVersion>
</PropertyGroup>
</Target>
<ItemGroup>
<Compile Remove="AccessControl\**" />
<EmbeddedResource Remove="AccessControl\**" />
<None Remove="AccessControl\**" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\common\Version.cs" Link="Properties\Version.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="4.8.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<Reference Include="MyEngine">
<HintPath>..\libs\NetStandard\MyEngine.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net45'">
<Reference Include="MyEngine">
<HintPath>..\libs\NET45\MyEngine.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
</Project>
The targets can be adapted to support multi-targeting like this:
<Target Name="ReadPackageVersionFromOutputAssemblySingleTfm" Returns="#(PackAssembly)" Condition="'$(IsCrossTargetingBuild)' != 'true'">
<GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
<Output TaskParameter="Assemblies" ItemName="PackAssembly" />
</GetAssemblyIdentity>
<PropertyGroup>
<PackageVersion>%(PackAssembly.Version)</PackageVersion>
</PropertyGroup>
</Target>
<Target Name="ReadPackageVersionFromOutputAssemblyMultipleTfms" Condition="'$(IsCrossTargetingBuild)' == 'true'">
<PropertyGroup>
<FirstTargetFramework>$([System.String]::Copy($(TargetFrameworks)).Split(';').GetValue(0))</FirstTargetFramework>
</PropertyGroup>
<MSBuild Projects="$(MSBuildProjectFullPath)" Targets="ReadPackageVersionFromOutputAssemblySingleTfm" Properties="TargetFramework=$(FirstTargetFramework)">
<Output TaskParameter="TargetOutputs" ItemName="PackAssembly" />
</MSBuild>
<PropertyGroup>
<PackageVersion>%(PackAssembly.Version)</PackageVersion>
</PropertyGroup>
</Target>
<Target Name="ReadPackageVersionFromOutputAssembly" DependsOnTargets="Build;ReadPackageVersionFromOutputAssemblySingleTfm;ReadPackageVersionFromOutputAssemblyMultipleTfms" />

.NET Core F# project will not write to TraceSource

I could not get my F# project to write to the TraceSource.
Here was my F# code:
use logFileStream = new FileStream("log.txt", FileMode.Append, FileAccess.Write)
(
use logFileListener = new TextWriterTraceListener(logFileStream)
(
let traceSource = TraceSource("Test", SourceLevels.All)
traceSource.Listeners.Add(logFileListener) |> ignore
traceSource.TraceEvent(TraceEventType.Verbose, 1, "This is a test.")
)
)
Here was my F# project:
<Project Sdk="FSharp.NET.Sdk;Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FSharp.Core" Version="4.1.*" />
<PackageReference Include="FSharp.NET.Sdk" Version="1.0.*" PrivateAssets="All" />
<PackageReference Include="System.Diagnostics.TextWriterTraceListener" Version="4.3.0" />
<PackageReference Include="System.Diagnostics.Tracing" Version="4.3.0" />
</ItemGroup>
</Project>
Why was log.txt empty?
I needed to add <DefineConstants>TRACE</DefineConstants> to a PropertyGroup within my project file.
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>

Resources