C
C#3mo ago
Valdiralita

creating a nuget for a custom msbuild task

I'm trying to follow the custom msbuild task tutorial here: https://learn.microsoft.com/en-us/visualstudio/msbuild/tutorial-custom-task-code-generation?view=vs-2022 My problem is that when using dotnet pack the resulting nupkg file doesnt contain any binaries. All required binaries are present in the ./bin/Release/netstandard2.0/ folder, they are just not packed into the nupkg. When inspecting the nupkg, there is no lib folder inside, i can see my .props file in the build folder though. Any ideas why that may happen?
9 Replies
Valdiralita
ValdiralitaOP3mo ago
I think it might be related to the Target CopyProjectReferencesToPackage . VS says that the target it depends on (ResolveReferences) is not defined.
MarkPflug
MarkPflug3mo ago
You don't want your assemblies to end up in the lib folder, as that would cause the consuming project to use it at runtime. An MSBuild package should only be loaded at build time. So, you want to have your binaries in a different location, such as under your build folder where your .props/.targets files live. I think you can do this by setting <BuildOutputTargetFolder>build</BuildOutputTargetFolder> in the .csproj for your task.
Valdiralita
ValdiralitaOP3mo ago
youre right, i meant to write "task", not lib
MarkPflug
MarkPflug3mo ago
Here is a project I created that does what you're looking for: https://github.com/MarkPflug/Sylvan.BuildTools.Resources/blob/main/source/Sylvan.BuildTools.Resources/Sylvan.BuildTools.Resources.csproj This .csproj has all the settings needed to produce a correct package. However, this task has no third-partyh dependencies, which might complicate things a bit.
GitHub
Sylvan.BuildTools.Resources/source/Sylvan.BuildTools.Resources/Sylv...
Build-time resource file support in C# projects. Contribute to MarkPflug/Sylvan.BuildTools.Resources development by creating an account on GitHub.
Valdiralita
ValdiralitaOP3mo ago
the problem seemed to be that i had a solution wide .props file that specified net8.0 and the msbuild task project overwrite it with netstandard2.0. after removing the net8.0 from the .props file it fixed the issue.
MarkPflug
MarkPflug3mo ago
As the article you linked mentioned, you can't use normal nuget package dependencies in an msbuild package, since there is no "nuget restore" for the msbuild steps Sounds like you got it figured out then?
Valdiralita
ValdiralitaOP3mo ago
yes, as i said, the problem was that the default was net8 and the task project overwrote it as netstandard2.0 seems to be a msbuild bug
MarkPflug
MarkPflug3mo ago
Task projects should be "netstandard2.0". Visual Studio builds using .net framework, not core, so it wouldn't be able to load a net8 library in msbuild
Valdiralita
ValdiralitaOP3mo ago
sure, the project always was netstandard2.0 just a .props file in a parent directory specified net8
Want results from more Discord servers?
Add your server