Hasan Hasanov
Hasan Hasanov

Reputation: 1159

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.

Upvotes: 12

Views: 19085

Answers (5)

Ajay Kopperla
Ajay Kopperla

Reputation: 459

  • We need to use visual studio installer to install the .netframework 3.5 , if the visual studio installer shows both options Visual Studio 2019 and Visual studio Build Tools 2017. follow below step
  • If you are using the Visual Studio 2019 ( mine was 16.11.3 but should work for all the versions). you will have Visual studio 2019 and Visual studio build tools 2017 .
  • Select the Visual Studio Build Tools 2017 => select modify => go to individual components => select .Net Framework 3.5 development tools
  • Then proceed with the installation. -Ideally it should work once you re open the Visual studio , if not restart the system

Upvotes: 0

Chris Baynes
Chris Baynes

Reputation: 51

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.

Upvotes: 5

N-ate
N-ate

Reputation: 6933

In my case the paths were correct, but visual studio needed to run under elevated permissions to access the file in question.

Upvotes: 1

BBR
BBR

Reputation: 51

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

Upvotes: 5

Hasan Hasanov
Hasan Hasanov

Reputation: 1159

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

Upvotes: 15

Related Questions