【问题标题】:How to reference an old assembly in ASP.NET Core (.NET Framework targeting) project?如何在 ASP.NET Core(.NET Framework 目标)项目中引用旧程序集?
【发布时间】:2017-12-31 18:42:50
【问题描述】:

我在一堆 .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 来构建它?

【问题讨论】:

  • AFAICT 正确的解决方案是升级 StyleCop.MsBuild 以支持现代版本的 .Net Framework / Core。

标签: asp.net-core stylecop


【解决方案1】:

正如@lionnnn 在他们的回答中所说,从 4.7.55 开始的 StyleCop 是not yet supported on .NET Core

我可以通过直接将我需要的项目本身的文件作为链接来解决这个问题:

.csproj:

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

这会将所需的文件编译到我的项目中,而不会带来所有依赖项。不是最好的解决方案,但这种解决方法可以满足我的需求。

【讨论】:

    【解决方案2】:

    我尝试安装 Nuget 包,但消息是它与 .net 核心不兼容。

    我的猜测是 stylecop 还没有移植到 .net 核心。

    .net core 和 .net 不一定相互兼容。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多