Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Task could not be loaded from assembly

I have an error in one of my projects at work. The error says:

Severity Code Description Project File Line Suppression State Error The "StyleCopTask" task could not be loaded from the assembly C:\Projects\Project Name\Source\\MSBuild\StyleCop\v4.7\StyleCop.dll. Could not load file or assembly 'Microsoft.Build.Utilities.v3.5, Version=3.5.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. DskDirectMarketing.Common

Here I can clearly see that there is problem in the relative path which VS is looking for StyleCop. Here is how it looks like:

<Import Project="$(SolutionDir)\MSBuild\StyleCop\v4.7\StyleCop.targets" />

and my SolutionDir declaration looks like this:

<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>

After some digging I noticed that in the error which prompts me there are 2 slashes:

C:\Projects\Project Name\Source\MSBuild\StyleCop\v4.7\StyleCop.dll

First thing I tried was to remove the dash from

<Import Project="$(SolutionDir)MSBuild\StyleCop\v4.7\StyleCop.targets" />

Id didn't worked. After that I tried to put the absolute path but I had 2 slashes again.

How can I resolve this issue? Any help would be appreciated.

like image 768
Hasan Hasanov Avatar asked Nov 22 '16 15:11

Hasan Hasanov


3 Answers

If you are using Windows 10, enable the .net framework 3.5 and if does not allow you to do so, open command prompt and run:

Dism /online /enable-feature /featurename:NetFX3 /All /Source:D:\sources\sxs /LimitAccess
like image 75
BBR Avatar answered Oct 19 '22 18:10

BBR


Based on @MaKCbIMKo's answer I installed .Net Framework 3.5 and this fixed my problem.

like image 13
Hasan Hasanov Avatar answered Oct 19 '22 20:10

Hasan Hasanov


If you're also using Visual Studio 2019 on Windows 10, you could try the following:

  1. Close your Visual Studio instance.
  2. Open Visual Studio Installer.
  3. On the version of Visual Studio that you're currently using, click on More and select Modify.
  4. Select the Individual components tab.
  5. Search for .NET Framework 3.5 development tools, select it and click on Modify.
  6. Wait for the modification to finish.
  7. Open your project in Visual Studio, then do a Clean, followed by a Build.
like image 3
Chris Baynes Avatar answered Oct 19 '22 19:10

Chris Baynes