Reputation: 1159
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
Reputation: 459
Upvotes: 0
Reputation: 51
If you're also using Visual Studio 2019 on Windows 10, you could try the following:
Upvotes: 5
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
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
Reputation: 1159
Based on @MaKCbIMKo's answer I installed .Net Framework 3.5 and this fixed my problem.
Upvotes: 15