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.
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
Based on @MaKCbIMKo's answer I installed .Net Framework 3.5 and this fixed my problem.
If you're also using Visual Studio 2019 on Windows 10, you could try the following:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With