VS Studio 2019 error when trying to publish self-contained - c#

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.

Related

Build a WPF application in VScode gave me error MSB4062

I am trying to perform a build on a WPF (.Net Core 3.1) in Visual Studio Code (not Visual Studio this time cause I need a more lightweight editor).Normally all my project can be built fine, but this WPF project gave me this following error:
C:\Program Files (x86)\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets\Microsoft.
WinFX.targets(225,9): error MSB4062: The "Microsoft.Build.Tasks.Windows.MarkupCompilePass1" task could not be loaded from
the assembly C:\Program Files %28x86%29\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk.WindowsDesktop\tools\netcoreapp2.1\PresentationBuildTasks.dll. Could not load file or assembly 'C:\Program Files
%28x86%29\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk.WindowsDesktop\tools\netcoreapp2.1\PresentationBuildTasks.dll'. The system cannot find the path specified.
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. [E:\ui_wpf_test\ui_wpf_test.csproj]
The build failed. Fix the build errors and run again.
I heard that it has to do with MSbuild, but I dont know how to correctly fix this
I found a solution on GitHub. You have to replace the following line of %ProgramFiles(x86)%\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets\Microsoft.WinFx.props:
<_PresentationBuildTasksAssembly Condition="'$(_PresentationBuildTasksAssembly)'==''">$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\tools\$(_PresentationBuildTasksTfm)\PresentationBuildTasks.dll'))</_PresentationBuildTasksAssembly>
Replace it with:
<_PresentationBuildTasksAssembly Condition="'$(_PresentationBuildTasksAssembly)'==''">$(MSBuildThisFileDirectory)..\tools\$(_PresentationBuildTasksTfm)\PresentationBuildTasks.dll</_PresentationBuildTasksAssembly>
This has eventually worked for me.
small bug. should be fixed in the new upcoming 3.1.103 instead of now 3.1.102.
Problem is the path Program Files (x86)' where(x86)is escaped to%28x86%29`, resulting in path not found.
temporary fix by just escaping the path:
Go to:
C:\Program Files (x86)\dotnet\sdk\3.1.102\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets
edit Microsoft.WinFx.props and use this _PresentationBuildTaskAssembly which has the Unescape for the path:
<_PresentationBuildTasksAssembly Condition="'$(_PresentationBuildTasksAssembly)'==''">$([MSBuild]::Unescape($([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\tools\$(_PresentationBuildTasksTfm)\PresentationBuildTasks.dll'))))</_PresentationBuildTasksAssembly>
It is possible that you can resolve it also by changing in visual studio the build to x64 instead of Any CPU/x86. With 64-bit this will use C:\Program Files\ instead of C:\Program Files (x86)\ and thus not have the 'bad' characters.

CS1705 error while adding a C++ project to solution

Hi and thanks in advance.
I'm using TFS build 2013 (team services, not on premise) to build my solution. After creating a new C++ project in the solution I'm unable to build successfully.
The error I'm getting on the build machine is:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis\Microsoft.CodeAnalysis.targets
(219): An error has occurred during compilation. error CS1705: Assembly 'Microsoft.Build.Utilities.Core,
Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' uses 'Microsoft.Build.Framework,
Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher
version than referenced assembly 'Microsoft.Build.Framework, Version=12.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis\Microsoft.CodeAnalysis.targets
(219): The "SetEnvironmentVariable" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name
of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask
interface. 3.) The task is correctly declared with <UsingTask> in the project file, or
in the *.tasks files located in the "C:\Program Files (x86)\MSBuild\14.0\bin\amd64" directory.
I've red about error CS1705 on the internet but I still don't understand why I get this error - the project is an empty project which has no references what so ever and no other project reference it either.
I'm targeting .NET framework 4.6.1 on all my C# projects and in my build definition I'm adding these msbuild arguments: /tv:14.0 /p:VisualStudioVersion=14.0 hence it uses the 2015's version of the c# compiler.
The target platform for this C++ project is VS 2015 (v140) as follows:
C++ project configuration
Needless to say that when I'm removing this project from the list of project to build (configuration manager) - the solution builds successfully.
Any help/clue would be greatly appreciated!
The problem was something other than what I thought it was. Seems it's got something to do with CodeAnalysis and some environment variable related to it.
In my build definition I'm disabling CodeAnalysis and even inside the C++ project properties It's explicitly disabled. After I commented out some attributes on the "SetCABuildNativeEnvironmentVariables" target inside this file on the build machine:
"C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis\Microsoft.CodeAnalysis.targets"
The problem disappered.
This is a nasty workaround however since I'm not fully aware of what's really happening.
Thanks a lot anyways!
Seems there are something still point to "Microsoft.Build.Framework, Version=12.0.0.0"
The /tv:14.0 command argument doesn't work as expected. See:
BuildActivity ignores ToolsVersion
As a workaround, you need to customize the build process template:
Open the template in Visual Studio and find the Run MSBuild for
Project MSBuild activity.
Set ToolVersion to "14.0".
Set ToolPath to target to MSBuild14 (by default: "C:\Program Files
(x86)\MSBuild\14.0\Bin").
Check in this build process template and re-queue the build.
You can also refer the answer from Marson in TFS 2013 building .NET 4.6 / C# 6.0

Application requires that assembly office version 12.0.0.0 be installed in GAC

I have a .csproj that I want to publish to a clickonce server.
When I publish the application from one development computer it works and the program can be started from the server without any problems.
I download the same project from svn to another computer and try to publish it. That step kinda works, i guess, since the program is published successfully without any errors.
But when I try to start the program from the server I get the error:
Application requires that assembly office version 12.0.0.0 be installed in the Global Assembly Cache(GAC) first.
Update: (also posted info in comments). I am receiving this warning on both machines though I don't know how to solve. But it's probably the cause of the problem I guess:
No way to resolve conflict between "office, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" and "office, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c". Choosing "office, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" arbitrarily.
1> Consider app.config remapping of assembly "office, Culture=neutral, PublicKeyToken=71e9bce111e9429c" from Version "12.0.0.0" [C:\Windows\assembly\GAC\office\12.0.0.0__71e9bce111e9429c\office.dll] to Version "14.0.0.0" [D:\Visual Studio\Visual Studio Tools for Office\PIA\Office14\office.dll] to solve conflict and get rid of warning.
So I finally solved this.
First I thougt I'd describe how the project looked. Under references there was no reference to the office.dll file though this actually ended up in the published directory when computer1, which was able to publish a working copy, published the project. Also under properties->publish->ApplicationFiles the office.dll was listed as exluded.
computer2, which couldn't publish a working project, had the same installed programs as computer1. So I tried to add the reference to office.ddl, set it to copy local and include it in applicationfiles. Now there was a office.dll copied to the published directory but the same error appeared. installed and re-installed a bunch of programs, no improvement. After I've been trying alot of randomstuff I ended up copying the dll from computer1, referenced it, set it to copy local and included it. And, voila, it worked?

Callisto multiple reference errors

Recently I tried to install callisto 1.1.0 and 1.2.6 for a windows store application. But after installation my application stopped running and popped out this error
Error 1 An assembly with the same simple name 'Callisto,
Version=1.2.6.0, Culture=neutral, PublicKeyToken=null has already been
imported. Try removing one of the references or sign them to enable
side-by-side. c:\Program Files (x86)\Microsoft
SDKs\Windows\v8.0\ExtensionSDKs\Callisto\1.2.6\References\CommonConfiguration\neutral\Callisto.dll Callisto_AppBar
I tried removing the dll files from the installed location and reinstalling the latest version of callisto. But still the same error is popping up. It would be great if someone could share a solution for it.
You can't have multiple versions of this library in your project...only one is permitted.

Migrator.NET MSBuild - Could not load file or assembly 'Migrator.Framework'

I've installed Migrator.NET using NuGet but when I attempt to run a migration using MSBuild I get the following error. I see that its having trouble accessing the Migrator.Framework assembly but I am unsure as to why or where specifically I need to put the DLL in order to get it to run.
C:\Users\Cody\src\App\App.Migrations\App.Migrations.csproj(64,5): error MSB4062: The "Migrator.MSBuild.Migrate" task could not be loaded from the assembly C:\Users\Cody\src\App\App.Migrations..\packages\MigratorDotNet.0.9.0.33276\tools\Migrator.MSBuild.dll.
Could not load file or assembly 'Migrator.Framework, Version=0.0.0.0, Culture=neutral, PublicKeyToken=3b3586e9632ecfce' 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.
Does anyone have any insight? I've spent far too long fiddling with this.
It turns out the issue was in fact that it was looking for version 0.0.0.0. I downloaded the project and recompiled the Migrator.Framework binary as version 0.0.0.0 as a quick fix. The real solution is recompiling Migrator.MSBuild.dll to look for the proper version of Migrator.Framework.
I'll see if this was a one-off error or if I can reproduce it, and submit it as a bug to the Migrator.NET team if it is in fact a bug with the NuGet package.

Categories