Custom MSBuild task fails to load `System.Runtime`
Hi, I'm making a custom MSBuild task that needs to load images and I was using
ImageSharp
for that. Before, I was targetting net6.0
and it worked when using dotnet build
or Rider, but I now had to change to netstandard2.0
as I need to support VS and forgot that VS only likes netstandard. After I changed to netstandard2.0
, a method using ImageSharp
started to throw the following exception while running the task, but only from VS (it still works when using dotnet build
):
7 Replies
Here's the method's code:
PackageReference to ImageSharp
How can I stop this exception from happening when building from Visual Studio?
VS only likes net standard?
Wut?
when using custom msbuild tasks
i might be wrong though
but when I tried using the net6.0 version it threw an error
Solved my issue
My build task is
ProjectReference
d by a net6.0
project that copies references to a custom folder, and it then passes a .targets
file to other projects for them to use the build task. Since the custom task was using <PackageReference Include="SixLabors.ImageSharp" />
, the reference was passed along to the net6.0
project which instead of using the netstandard2.0
version of ImageSharp used the netcoreapp3.1
version of ImageSharp. That version was then copied next to the BuildTools.dll
file so that the references to ImageSharp were resolved. As it was the netcoreapp3.1
version, it failed when building from VS (since it uses net framework), so it threw the system.runtime error.
I fixed this by adding PrivateAssets="all"
to the ImageSharp PackageReference
(in the custom build tool project), adding a <PackageReference Include="SixLabors.ImageSharp" Version="2.1.5" GeneratePathProperty="true" PrivateAssets="all" ExcludeAssets="all" />
just to get the path to the dll of imagesharp, and then adding a copy task to copy the netstandard2.0
dll next to the BuildTools.dll
(<Copy SourceFiles="$(PkgSixLabors_ImageSharp)\lib\netstandard2.0\SixLabors.ImageSharp.dll" DestinationFolder="$(_ActualOutputDirectory)/Libraries/tModLoader.BuildTools/1.0.0/" SkipUnchangedFiles="True" />
)