question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MSB4181 vis-a-vis custom MSBuild task targets

See original GitHub issue

Borderline to do with MSBuild as much as it is the SDK.

I have a scenario with a netcoreapp3.1 targeted (WinForms, i.e. WinExe) project that is generating an MSB4181 error.

Generally speaking, as tooling, the bumps work, has been proven to do so over a range of scenarios from netstandard to netcoreapp to classical desktop .NET Framework scenarios; but in this scenario we are bumping into the MSB4181.

Literally the project in question is:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<!-- ... -->
</Project>

I have discovered the SDKs in my syste mare currently:

C:\>dotnet --list-sdks
2.1.518 [C:\Program Files\dotnet\sdk]
3.1.402 [C:\Program Files\dotnet\sdk]

However, I think that probably the build is happening under 3.1.402, which, from at least a couple of other items, is thought to be that the SDK itself broke something along the way, with at least one workaround supposing global.json. Possibly, also, runtimeconfig.json may also be used to workaround the issue.

Assuming either or both of these would successfully workaround the issue, the question for me then is, to which SDK. I don’t think my custom MSBuild task assembly necessarily cares what that is, as long as there is support for netstandard2.0. Thinking forward, then there is also the problem of the hole in the middle; what to do with instances of the 3.1.402 SDK, which apparently cause the issue. Maybe this is already supported by global.json and/or runtimeconfig.json, but I am less familiar with those protocols.

Attached is a repro of the issue. Observing the results of the build in a couple of local BAV turns, it seems like the tooling does try to perform what it needs to perform, however, MSBuild is failing to relay the item specs properly via its targets, which tells me that probably something integration-wise broke in terms of MSBuild more than anything else.

bavtest.zip

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mwpowellhtxcommented, Nov 13, 2020

@marcpopMSFT Ah! 💡 Totally fogotten about that line, appreciate the code review. I’ll have a closer look at it.

1reaction
marcpopMSFTcommented, Nov 13, 2020

I can confirm through the binlog that the BumpVersionSpec property is set identically for both Sdk imports. Poking through the code, I think you want to take a look at this line in BumpAssemblyVersions which seems to special case the Microsoft.NET.Sdk: https://github.com/mwpowellhtx/BumpAssemblyVersions/blob/099e32fb9570e5fc1ae501b4ec5230f9567ceed9/src/BumpAssemblyVersions/BumpVersionTask.cs#L306

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create a custom task for code generation - MSBuild
In this tutorial, you'll create a custom task in MSBuild in C# that handles code generation, and then you'll use the task in...
Read more >
Use custom MSBuild tasks from the same solution?
We tried this and we found that you have to place the UsingTask at the top of the project file (and have all...
Read more >
Task Writing - MSBuild
Tasks are contained in targets. A library of typical tasks is included with MSBuild, and you can also create your own tasks.
Read more >
Implementing and Debugging Custom MSBuild Tasks
targets files. They will be compiled into tasks by the RoslynCodeTaskFactory and executed by MSBuild when run. This is great for drafting ideas ......
Read more >
Shipping a cross-platform MSBuild task in a NuGet package
MSBuild allows users to write and register their own tasks. Tasks, unlike targets, can be written in C# and can perform build operations ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found