-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Task failing unexpectedly on .Net 6.0 platform #9947
Comments
@serhiikuksov3shape how are you invoking the build? |
You need just to rebuild the solution to see an error. |
@serhiikuksov3shape exactly how please? What command line are you invoking? |
I was building this in Visual Studio 2022, by right click on Solution --> Rebuild. Also, this can be achieved with |
No need, that reveals the problem: you're running the build from a .NET Framework process, so it can't run a .NET 6 DLL. If you want your task to work in that situation you must target .NET Framework 4.7.2. If you can run all builds with It may be possible at some point in the future to run a .NET 6 task in these scenarios; that's tracked as #4834. |
Hi @rainersigwald, Is there any other option to run c# code on the "afterbuild" event, in Visual Studio (.NET 6 only)? |
If you build your code as an executable, you can use the Exec task to run it from the post-build target. But then it cannot use the MSBuild API for parameters and logging. Another option might be to target netstandard2.0 in the task project, but then the project would not be able to reference NuGet packages that support only net6.0. IIRC, referencing Microsoft.Build.Utilities.Core should be OK, though. |
Thank you for your answers, we already found a workaround for this issue, so it can be closed. |
Issue Description
After the migration from .Net48 to .Net6.0 I`m getting weird errors on a post-build event that triggers a custom task.
Error MSB4018 The "PostBuildTask" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at Core.PostBuildTask.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()
My csproj file:
Steps to Reproduce
Issue.zip
Expected Behavior
Task is running without errors
Actual Behavior
Error MSB4018 The "PostBuildTask" task failed unexpectedly.
Analysis
No response
Versions & Configurations
No response
The text was updated successfully, but these errors were encountered: