2017-03-17 2 views
2

Ich habe eine ziemlich einfache Klasse, die von ITask erbt, und wird als Build-Task zum Aktualisieren von Versionen ausgeführt (VersionUpdater.dll). Der Eintrag der Projektdatei lautet wie folgt:ITask schlägt beim Laden des .NET Core-Projektprozesses fehl

<UsingTask TaskName="VersionUpdater" AssemblyFile="VersionUpdater.dll" /> 
<Target Name="BeforeBuild"> 
    <VersionUpdater /> 
</Target> 

Dies ist für reguläre .Net-Projekte völlig in Ordnung; jedoch habe ich versucht, es in .Net Core-Projekt Build-Tasks zu laden und bekam dies:

Severity Code Description Project File Line Suppression State Error MSB4062 The "VersionUpdater" task could not be loaded from the assembly C:...\VersionUpdater.dll. Could not load file or assembly 'file:///C:...\VersionUpdater.dll' or one of its dependencies. The system cannot find the file specified. Confirm that the 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.

Ok, also ich meine, vielleicht die DLL gebaut werden muss jetzt .Net-Core verwenden, so habe ich, und erstellt VersionUpdater.Core.dll (AssemblyFile="VersionUpdater.Core.dll") und habe diesen Fehler:

Severity Code Description Project File Line Suppression State Error MSB4062 The "VersionUpdater" task could not be loaded from the assembly C:...\VersionUpdater.Core.dll. Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Confirm that the 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.

Wie gesagt, funktioniert der Code für normale .NET-Projekte. Es möchte einfach nicht mit .Net Core-Projekten arbeiten. Alles was ich vermisse? Ist es ein Fehler, dass System.Runtime nicht für .Net Core gefunden wurde?

(Quelle ist hier: https://github.com/rjamesnw/VersionUpdater)

Antwort

1

Um eine Aufgabe der Arbeit mit beiden 'Dotnet msbuild' zu machen und MSBuild.exe, müssen Sie die Aufgabe für .NET Framework überqueren kompilieren und eine .NET-Core- kompatibles Framework wie .NET Standard. Dann müssen Sie variieren, welche Task Assembly lädt und den Laufzeittyp von MSBuild. Sie können dies mithilfe von MSBuildRuntimeType erkennen. Beispiel:

<PropertyGroup> 
    <TaskAssembly Condition=" '$(MSBuildRuntimeType)' == 'Core'">.\bin\Debug\netstandard1.6\MyTaskAssembly.dll</TaskAssembly> 
    <TaskAssembly Condition=" '$(MSBuildRuntimeType)' != 'Core'">.\bin\Debug\net46\MyTaskAssembly.dll</TaskAssembly> 
    </PropertyGroup> 

    <UsingTask TaskName="MyTaskName" AssemblyFile="$(TaskAssembly)" /> 

In diesem Blogbeitrag finden Sie eine ausführliche Erläuterung und ein Beispiel. http://www.natemcmaster.com/blog/2017/07/05/msbuild-task-in-nuget/

Verwandte Themen