Search code examples
asp.net-corestylecop

How to reference an old assembly in ASP.NET Core (.NET Framework targeting) project?


I'm building an ASP.NET Core project (with target framework as .NET Framework 4.5.2), in a solution of a bunch of .NET Framework projects. I'm referencing one of the projects that uses StyleCop.MsBuild. However, when I do a dotnet build, I'm getting:

C:\MySolution\nupkgs\StyleCop.MSBuild.4.7.54.0\build\StyleCop.MSBuild.Targets(101,5): error MSB4062: The "StyleCopTask" task could not be loaded from the assembly
C:\MySolution\nupkgs\StyleCop.MSBuild.4.7.54.0\build\..\tools\StyleCop.dll. Could not load file or assembly 'System.Windows.Forms, Version=2.0.0.0, 
Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file 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. [
C:\MySolution\src\MyProject\MyProject.csproj] 

Where MyProject is the project I'm trying to reference.

I've tried including System.Windows.Forms as a dependency, but it's version is 4.0.0.0 rather than 2.0.0.0, so that didn't seem to work.

Is there anyway to reference System.Windows.Forms to get this to build?


Solution

  • As @lionnnn stated in their answer, StyleCop as of 4.7.55 is not yet supported on .NET Core.

    I was able to work around this by directly including files I needed from the project itself as a link:

    .csproj:

      <Compile Include="..\MyProject\MyFile.cs">
          <Link>MyProject\%(FileName)%(Extension)</Link>
      </Compile>
    

    This compiled the needed files into my project without bringing over all the dependencies. Not the greatest solution, but this workaround is okay for my needs.