2017-07-25 128 views
0

我在一堆.NET Framework项目的解决方案中构建了一个ASP.NET Core项目(目标框架为.NET Framework 4.5.2)。我引用了其中一个使用StyleCop.MsBuild的项目。但是,当我做了dotnet build,我越来越:如何引用ASP.NET Core(.NET Framework定向)项目中的旧程序集?

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得到这个建立?

+0

AFAICT这里的适当解决方案是升级'StyleCop.MsBuild'以支持.Net Framework/Core的现代版本。 – Thebluefish

回答

1

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

我能够通过直接,包括我从项目本身为纽带所需要的文件,以解决此问题:

的.csproj:

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

这编译所需的文件到我的项目没有带来过所有的依赖关系。不是最好的解决方案,但是这种解决方法对我的需求没有问题。

1

我试图安装Nuget包,并且这条消息是它与.net核心不兼容。

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

.net核心和.net不一定相互兼容。

+0

幸运的是,随着.NET Standard 2.0和.NET Core 2.0的发展,这将会发生变化:https://docs.microsoft.com/en-us/dotnet/standard/net-standard –

相关问题