asp.net-core - 如何在 ASP.NET Core(.NET Framework 目标)项目中引用旧程序集?

标签 asp.net-core stylecop

我正在一堆 .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/

相关文章:

c# - 如何在 Asp.Net Core MVC 的 ExceptionFilter 中返回带有模型的 View

c# - EF Core FK 对备用键的约束

asp.net - 无法在两个服务之间进行通信

visual-studio - 禁用 StyleCop 规则

c# - 无法使 StyleCop 错误显示为构建错误(而不是警告)

c# - 发布 dot net core 2 应用程序后启动应用程序时出错

c# - 在正文中使用 int/string (简单类型)发布到 asp.net core web api 2.1 不起作用

windows-installer - Visual Studio 安装项目启动条件以检查 StyleCop

c# - 通过 NuGet 为 .net 核心项目提供代码分析规则集

c# - StyleCop 4.7 是否与 C# 6.0 代码兼容