我正在一堆 .NET Framework 项目的解决方案中构建一个 ASP.NET Core 项目(目标框架为 .NET Framework 4.5.2)。我正在引用使用 StyleCop.MsBuild 的项目之一。但是,当我执行 dotnet build
时,我得到:
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]
其中 MyProject
是我尝试引用的项目。
我尝试将 System.Windows.Forms
作为依赖项包含在内,但它的版本是 4.0.0.0 而不是 2.0.0.0,因此这似乎不起作用。
有没有办法引用System.Windows.Forms
来构建它?
最佳答案
正如 @lionnnn 在他们的回答中所述,截至 55 年 7 月 4 日的 StyleCop 为 not yet supported on .NET Core 。
我可以通过直接将项目本身所需的文件作为链接包含来解决此问题:
.csproj:
<Compile Include="..\MyProject\MyFile.cs">
<Link>MyProject\%(FileName)%(Extension)</Link>
</Compile>
这将所需的文件编译到我的项目中,而没有引入所有依赖项。这不是最好的解决方案,但这个解决方法可以满足我的需求。
关于asp.net-core - 如何在 ASP.NET Core(.NET Framework 目标)项目中引用旧程序集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45310071/