I'm having an issue trying to build a dotnet core project from command line that has these references:
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.6.1" />
<PackageReference Include="Microsoft.Net.Compilers" Version="2.6.1" />
For whatever reason it keeps saying Microsoft.Build.Tasks.CodeAnalysis.dll assembly has already been loaded. Here is the exact error message:
C:\Users.nuget\packages\microsoft.net.compilers\2.6.1\tools\Microsoft.CSharp.Core.targets(84,5):
error MSB4062: The "Microsoft.CodeAnalysis.BuildTasks.Csc" task could
not be loaded from the assembly
C:\Users.nuget\packages\microsoft.net.compilers\2.6.1\build..\tools\Microsoft.Build.Tasks.CodeAnalysis.dll.
Assembly with same name is already loaded 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.
When I go to that project directory and run dotnet build It has no issues building the project, but when I run dotnet build against the solution that's when I get this error. If I build the solution from Visual Studio it also has no issues building. Really strange behavior, not quite sure how to get around it.
Related
Facing following issue after deploying app to azure app service:
Unhandled exception. System.IO.FileNotFoundException: Could not load
file or assembly 'Microsoft.Data.SqlClient, Version=5.0.0.0,
Culture=neutral, PublicKeyToken=***********'. The system cannot find
the file specified.
Locally everything works as fine.
Microsoft.Data.SqlClient presented in site/wwwroot
Runtime Stack: Dotnetcore - 6.0
Main app and all class libs on .net6
Server Operating System: Linux
Microsoft.Data.SqlClient presented as reference from Microsoft.EntityFrameworkCore.SqlServer (v.7.0.2)
Tried different kinds of Nuget Packages versions - still have same issue
Tried to install Microsoft.Data.SqlClient (latest version & 5.0.0.0) directly into projects - still the same
The solution for us was to:
Locate the actual DLL file (Microsoft.Data.SqlClient.dll) on the developer's desktop filesystem (easy to find; once you're referenced it using NuGet it gets copied to multiple places)
Add it to the web project (we placed it right in the root)
Mark it (via Properties tool window) as Copy Always
Step 3 results in our .csproj file looks like this:
<ItemGroup>
<None Update="Microsoft.Data.SqlClient.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
I'm using command dotnet build in order to build a game in the MonoGame framework in Ubuntu 20.04 using .NET 5.0.
It was fine in Windows, but now that I'm using it here, it gives me this error:
error CS1069: The type name 'PrivateFontCollection' could not be found in the namespace 'System.Drawing.Text'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly. [/home/mrwoto/Ali/Programming/csharp/SAO/SAO/SAO.csproj]
So, is there anyway to resolve it? How can I add a reference to it in .csproj file?
One option is to add it from the terminal with
dotnet add package System.Drawing.Common
After this, you should be able to see something like the following in the .csproj file.
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
Please note that dotnet add is more than just adding some text to csproj.
From dotnet add package:
The dotnet add package command provides a convenient option to add a package reference to a project file. After running the command, there's a compatibility check to ensure the package is compatible with the frameworks in the project. If the check passes, a <PackageReference> element is added to the project file and dotnet restore is run.
I wrote a c# console application that I want to compile for a linux machine. When I use the following command in the console, I get this error:
dotnet publish -r linux-x64 --self-contained true
C:\Program Files\dotnet\sdk\3.1.300\Microsoft.Common.CurrentVersion.targets(3983,5): error MSB4062: The "Microsoft.Build.Tasks.ResolveManifestFiles" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. Confirm that the <UsingTask> 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. [X:\Coding\Visual Studio 2019\Projects\firstDiscordBot\firstDiscordBot\firstDiscordBot.csproj]
I read through a lot of similar questions but none of the solutions worked for me. I tried deleting the .vs folder inside my solution's project folder and did Clean and Build and I tried entering Install-Package MSBuildTasks into the NuGet Package Manager Console and then rebuilding my project.
(Error message in plain text, maybe a bit easier to read:)
C:\Program Files\dotnet\sdk\3.1.300\Microsoft.Common.CurrentVersion.targets(3983,5): error MSB4062: The "Microsoft.Build.Tasks.ResolveManifestFiles" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. 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. [X:\Coding\Visual Studio 2019\Projects\firstDiscordBot\firstDiscordBot\firstDiscordBot.csproj]
[Edit]
I did some experiments and now the error message says the following:
C:\Program Files\dotnet\sdk\3.1.300\Microsoft.Common.CurrentVersion.targets(3975,5): error MSB4062: The "Microsoft.Build.Tasks.SignFile" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. 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. [X:\Coding\Visual Studio 2019\Projects\firstDiscordBot\firstDiscordBot\firstDiscordBot.csproj]
I guess the error is basically the same, it probably won't matter much.
I also did some more research and I tried several more things, such as using the 'Publish' feature when right-clicking my project in the Solution-Explorer and reinstalling the SDK. I also verified all my files several times but none of the above helped.
I just want to mention that every little suggestion would be greatly appreciated as this is the first time, that I don't seem to able to fix the problem, even after multiple hours of research and dedication. So if there's anything you think I could do, I would be very happy.
For anyone with the same issue, I fixed it. My problem was simply that I was using a .NET-Framework project instead of .NET-Core. Watch out on that.
I have AspNet.MVC application and want to build MVC views during the build (only in Release configuration).
I create this target
<Target Name="BuildViews" Condition="'$(configuration)'=='Release'" AfterTargets="Build">
<AspNetCompiler VirtualPath="/" PhysicalPath="$(ProjectDir)" />
</Target>
In Debug configuration it builds
In Release it fails with error
error MSB4062: The "Microsoft.Build.Tasks.AspNetCompiler" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. Confirm that the <UsingTask> 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.
Installing Microsoft.Build.Tasks.Core, adding UsingTask and other manipulations doesnt help(
Maybe anyone knows the solution?
Target framework - new 4.8
C# version - 8
IDE - JetBrains Rider 2019.3.1
MSBuild Path - C:\Program Files\dotnet\sdk\3.1.101\MSBuild.dll
Project format - Microsoft.NET.Sdk (.net core format)
Also, i try to change MSBuild Path (in rider settings)
If i change it to exe-file in rider folder C:\Program Files\JetBrains\JetBrains Rider 2019.3.1\tools\MSBuild\Current\Bin\MSBuild.exe, it works
But this is not a solution, because it doesnt work on TeamCity agents, where rider is not installed
Just had the same issue with the BuildTools in Team City... Depending on what build tools you need there are different paths to it as some exist in \Microsoft Visual Studio\2019\Professional\MSBuild\ and some are in MSBuild\2019\<path>. For me this issue was resolved by updating my .config towards VS and not the build tools.
I'm a newcomer to Xunit and I'm trying to run it via MSBuild. Following the documentation, here is my build script so far:
<UsingTask AssemblyFile="..\packages\xunit.runner.msbuild.*\build\*\xunit.runner.msbuild.dll"
TaskName="Xunit.Runner.MSBuild.xunit"/>
<Target Name="Test">
<xunit Assemblies="bin\$(Configuration)\Core.dll"/>
</Target>
When I run MSBuild on the .csproj, however, it gives me the following error:
error MSB4127: The "Xunit.Runner.MSBuild.xunit" task could not be instantiated from the
assembly "C:\Users\James\libvideo\tests\Core\packages\xunit.runner.msbuild.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.runner.msbuild.dll".
Please verify the task assembly has been built using the same version of the Microsoft.Build.Framework
assembly as the one installed on your computer and that your host application is not missing
a binding redirect for Microsoft.Build.Framework. Unable to cast object of type
'Xunit.Runner.MSBuild.xunit' to type 'Microsoft.Build.Framework.ITask'.
I've checked that the path it's looking for exists, and I've also followed the steps here. No luck, however. What can I do to resolve this?
This error is normally due to a mismatch in your MSBuild Tools Version. This is defined in the <Project> root element. The tools version you are running is from a version of the ITask interface different from that of the xunit runner so without an assembly binding redirect, it cannot cast between the different versions of ITask.
https://msdn.microsoft.com/en-us/library/bb383796.aspx