C# MSBuild: Microsoft.CodeAnalysis.BuildTasks.Csc task could not be loaded - c#

I wrote a small C#/WPF application that builds a list of solutions with MSBuild.
These solutions can easily be built with Visual Studio 2017.
However, if I build the same solutions with MSBuild, I get the following error:
The "Microsoft.CodeAnalysis.BuildTasks.Csc" task could not be loaded
from the assembly C:\Program Files (x86)\Microsoft Visual
Studio\2017\Professional\MSBuild\15.0\Bin\Roslyn\Microsoft.Build.Tasks.CodeAnalysis.dll.
Could not load file or assembly 'Microsoft.Build.Utilities.Core,
Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or
one of its dependencies. The system cannot find the file specified.
Confirm that the declaration is correct, that the assembly
and all its dependencies are available, and that the task contains a
public class that implements Microsoft.Build.Framework.ITask.
What is striking here is that version 14.0.0.0 is being searched for, although Visual Studio 2017 and version 15.0 are being used.
To narrow down the problem, I build a simple C# console application that only outputs a Hello World string. But I get the same error message.
I have the following constellation:
Visual Studio 2017
NuGet packages: Microsoft.Build, Microsoft.Build.Framework, Microsoft.Build.Tasks.Core and Microsoft.Build.Utilities.Core version 15.9.20 and Microsoft.Net.Compiler version 2.10.0.
I read here that
The Microsoft.Net.Compilers package overrides (by setting properties
in your project file) the default version of Roslyn included with
MSBuild / Visual Studio.
A downgrade of the Microsoft.Net.Compiler to version 2.8.2 as suggested here does not change the bug.
How can I make sure that I build with the right version?

Related

Could not load file or assembly System.Threading.Tasks.Extensions

Well I have a problem, we upgraded the .net framework from version 4.0 to version 4.6 of .net, I have about 9 projects running and I had to install masstransit and autofac in 2 projects, this caused some libraries to be updated or installed in other projects.
At the moment in one of the projects(Team.Services) I have installed the 4.5.2 version of the library System.Threading.Tasks.Extensions, before of this I had the version 4.2.0.0, but now I update this. The image below you can see that it is version 4.5.2.
Now when I see the references of the project I can see that I do not have the correct version referenced, it is as if another dll was installed
look for the solution(link below) in other places, also try to change the version in the app.config check the version in the package.config clear the nuget cache and reinstall everything. and it is not working, it keeps looking for the old dll and for this reason it doesn't find the new dll, besides the installations seem to be a different version.
DLL hell - Could not load file or assembly System.Threading.Tasks.Extensions
This is the error:
System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
Source=Team.Services
StackTrace:
at Team.Services.ServiceFactory.StartServices(String applicationDirectory) in C:\Users\amilkar.contreras\source\repos\TFS.TeamServices\Common\Team.Services\ServiceFactory.vb:line 110
at Team.ServiceHost.Service.OnStart(String[] args) in C:\Users\amilkar.contreras\source\repos\TFS.TeamServices\Hosts\TeamServiceHost\Service.vb:line 25
at Team.ServiceHost.Service.Start(String[] args) in C:\Users\amilkar.contreras\source\repos\TFS.TeamServices\Hosts\TeamServiceHost\Service.vb:line 34
at Team.ServiceHost.Program.Main(String[] args) in C:\Users\amilkar.contreras\source\repos\TFS.TeamServices\Hosts\TeamServiceHost\Program.vb:line 41
You can have a try the possible solution to solve it:
Confirm the Package Management is Package.config in visual studio, then reinstall this package again
delete .vs folder then restart visual studio
Remove this dll manually, then add the new dll as reference manually

SonarQube doesnt find Microsoft.CodeAnalysis 1.3.1.0 but it is installed

I have tried to run a SonarQube scan on my C# projects. I have 3 projects and 1 solution file.
I run:
SonarScanner.MSBuild.exe begin /o:"xxxxxxxxx" /k:"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
/d:sonar.host.url="https://sonarcloud.io" /d:sonar.login="xxxxxxxxxxxxxxxxxxxxxxxxxxx"
MSBuild.exe Cake.Framework.sln /t:Rebuild
SonarScanner.MSBuild.exe /d:sonar.login="xxxxxxxxxxxxxxxxxxxxxxx" end
Then I see on my cmd:
SonarScanner for MSBuild 4.10
Using the .NET Framework version of the Scanner for MSBuild
Pre-processing started.
Preparing working directories...
Updating build integration targets...
Fetching analysis configuration settings...
Provisioning analyzer assemblies for cs...
Installing required Roslyn analyzers...
Provisioning analyzer assemblies for vbnet...
Installing required Roslyn analyzers...
Pre-processing succeeded.
C:\Users\santi\Desktop\20200422_Cake.Framework-master>MSBuild.exe Cake.Framework.sln /t:Rebuild
Microsoft (R) Build Engine, versiĆ³n 14.0.23107.0
Everything seems fine but suddenly I got like 1000+ warnings like this one:
CSC : warning CS8032: Couldnt create an analyzer instance
SonarAnalyzer.Rules.CSharp.PartCreationPolicyShouldBeUsedWithExportAttribute from
C:\Users\santi\AppData\Local\Temp\.sonarqube\resources\0\SonarAnalyzer.CSharp.dll : Could not load
file or assembly 'Microsoft.CodeAnalysis, version= 1.3.1.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file
specified. [C:\Users\santi\Desktop\20200422_Cake.Framework-master\Cake.Framework\Cake.Framework.csproj]
I already have installed the Microsoft.CodeAnalysis v 1.3.1 on all my 3 projects using the NuGet Manager.
What I'm missing?
I'm using .NET Framework 4.8, MSBuild 14.0, Visual Studio 2019
You don't need to install the code analysis NuGet packages in your projects.
What matters is the version of the code analysis assemblies that ship with the version of MSBuild you are using to build your solution. Check which version of MSBuild you are using (msbuild -ver). It needs to 14.0.25420.1 or later.

microsoft.vsa.dll error in VS2019 Comm but not in VS2013 Pro

I have legacy code that is currently building and running in Visual Studio 2013 Pro with .NET Framework 4 as expected. This C# code is in a single file and references a single .dll (VmfgInventory.dll) from a third party. The dll is added as a reference in the project.
I created a new project in Visual Studio 2019 Community Ed. Then copied the C# file from the VS2013 Pro project into the VS2019 Comm project. Next, I added copied the VmfgInventory.dll from the bin\Debug directory of VS2013 and added it to the bin\Debug directory of VS2019 and added it as a reference.
I then executed the exact same code in VS2019 and it crashes. I receive the following System.IO.FileNotFoundException
Message "Could not load file or assembly 'Microsoft.Vsa, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified."
I don't understand it, it's the exact same development machine. I've looked all over my machine and the only thing that I can find that matches Microsoft.Vsa is a version 8 of this dll that is under .NET Framework 2.
What could I possibly be overlooking? What allows the same code and referenced dll to work in VS2013 but not in VS2019?

Could not load file or assembly "CerfSharp.Core.dll" or one of its dependencies. The specified module could not be found

I have installed CerfSharp using the NuGet Pakage Manager and published a simple project that loads a ChromiumWebBrowser instance using the OneClick publish wizard.
However when installing the publised application the following error is diplayed "Could not load file or assembly "CerfSharp.Core.dll" or one of its dependencies. The specified module could not be found." if I click "ok" and run the application the ChromeWebBrowser doesn't work.
error screenshot
Can anyone provide the steps necessary in order to correctly build and pack the necessary files?
Other References:
https://ourcodeworld.com/articles/read/173/how-to-use-cefsharp-chromium-embedded-framework-csharp-in-a-winforms-application
Could not load file or assembly 'CefSharp.dll' or one of its dependencies
[System Info]:
Cef version: 63.0.0.0
OS:
Windows 10 x64 [Version 10.0.16299.248]
Visual Studio Version:
Microsoft Visual Studio Community 2017
Version 15.0.26228.12 D15RTWSVC
Microsoft .NET Framework
Version 4.7.02556

How to use MSBuild with WPF project that references net standard projects

We're creating a new Windows application with a WPF interface. For various reasons, we are attempting to make all of the supporting libraries run on net standard 2.0.
So the WPF project, Foo, references .NET Standard 2.0 projects from the same solution.
My problem is with getting the solution to build on the TeamCity build server.
msbuild gives an error when building the solution (works fine in Visual Studio 2017).
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFx.targets(268,9): error MC1000: Unknown build error, 'Cannot resolve dependency to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.' [Src\Foo\Foo.csproj]
If I use nuget to add NetStandard.Library to the Foo project, then I get a different error from msbuild (still works fine in visual studio).
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\NuGet\15.0\Microsoft.NuGet.targets(178,5): error : Your project.json doesn't have a runtimes section. You should add '"runtimes": { "win": { } }' to your project.json and then re-run NuGet restore. [Src\Foo\Foo.csproj]
There isn't a projects.json file.
It's running with 15.0 version of msbuild
External Program Failed: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MsBuild.exe (return code was 1)
Starting with a fresh build server solved the problem. I guess there were too many versions of msbuild and visual studio or SDKs or something on the old ones.
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFx.targets(268,9): error MC1000: Unknown build error, 'Cannot resolve dependency to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.' [Src\Foo\Foo.csproj]
The error message indicates you are using MSBuild for .NET Framework 4.0 to attempt to compile your assembly.
You should use dotnet msbuild to compile your .NET Standard 2.0 library and do note you need to have the .NET Core 2.0 SDK installed on the build machine.
dotnet msbuild /p:Configuration=Release
A simple way to install the .NET Core 2.0 SDK remotely on a CI server is to execute the dotnet-install script.
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\NuGet\15.0\Microsoft.NuGet.targets(178,5): error : Your project.json doesn't have a runtimes section. You should add '"runtimes": { "win": { } }' to your project.json and then re-run NuGet restore. [Src\Foo\Foo.csproj]
This error indicates your build server has a preview version of the .NET Core SDK on your server that uses project.json format. You will need the .NET Core 2.0 SDK in order to build.

Categories

Resources