1

I'm running MSBuild via command line on a customer configuration (like Debug, Release that you see in Visual Studio, except I'm using my own one).

MSBuild build.msbuild /p:Configuration=Dev ...blah  

C:\myproject\packages\PostSharp.4.3.9-alpha\tools\PostSharp.targets(422,5): error MSB4036: The "GenerateBindingRedirects" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name o f the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with in the project file, or in the *.tasks files located in the "C:\windows\Microsoft.NET\Frame work64\v4.0.30319" directory. [path to my proj file]

This normally works fine, but when I have postsharp it's throwing an error as you can see above. When I replace Dev in the /p:Configuration with Debug or Release they're working fine.

I checked the .csproj and nothing special is being added by Release that's not in my Dev configuration. What should I do to fix this? I tried copying the contents of the postsharp package directory into the bin\Dev folder but it's still not able to find the tasks.

8
  • That error probably indicates that a <UsingTask> element is being evaluated differently between the configurations. I would recommend diffing the preprocessed MSBuild project for the project in question--that is, compare the output of msbuild /pp:debug.proj path\to\project.csproj /p:Configuration=Debug and msbuild /pp:Dev.proj path\to\project.csproj /p:Configuration=Dev Feb 10, 2017 at 21:15
  • I'm actually unable to run it. I have toolset 12 which doesn't seem to support that pp flag.
    – arviman
    Feb 13, 2017 at 12:12
  • Are you aware that this is a year old alpha version? Have you tried upgrading the package? Feb 19, 2017 at 21:01
  • @DanielBalas are you referring to MSBuild or Postsharp?
    – arviman
    Feb 20, 2017 at 6:19
  • @arviman PostSharp Feb 21, 2017 at 8:47

2 Answers 2

1

I ran into this error in my .NET 4.0 project upgrading PostSharp from 2.1.6 to 6.0.27, launching the Release build with a script suddenly MSBuild (version 4.7.3056) stopped to work.

The problem is due to the task GenerateBindingRedirects declared inside PostSharp.targets (in package directory) which hasn't a corresponding <UsingTask TaskName="Microsoft.Build.Tasks.GenerateBindingRedirects" inside the .csproj.

Apparently the fastest way to "solve" is to add <PostSharpDisableDefaultBindingRedirects>True</PostSharpDisableDefaultBindingRedirects> inside the PostSharp.Custom.targets, as suggested here http://doc.postsharp.net/assembly-binding-resolution. But depending on the project it could be dangerous.

It didn't work for me because the .NET framework of my project is too old, but in theory a solution could be to add the package to the project and declaring the UsingTask element inside the .csproj:

Install-Package Microsoft.Build.Tasks.Core -Version 15.1.0

<UsingTask TaskName="Microsoft.Build.Tasks.GenerateBindingRedirects" AssemblyName="Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Condition="'$(MSBuildAssemblyVersion)' != ''" />

Other workarounds are the removal of element GenerateBindingRedirects declared inside PostSharp.targets (adding this file to the git tracked files), or to add an override of that element in the .csproj files of the projects where there is the problem (something like this):

<Target Name="PostSharpGenerateBindingRedirects" DependsOnTargets="ResolveAssemblyReferences" Inputs="$(MSBuildAllProjects);@(AppConfigFile);$(ResolveAssemblyReferencesStateFile);$(IntermediateOutputPath)" Outputs="$(_DefaultPostSharpHostConfigurationFile)" />
0

We just ran into the same situation. Upgrading from PostSharp 2 to 6.0.33. Our Jenkins build failed with this same error when building the Release configuration.

@Mauro Picotti suggestions were helpful, however installing the Microsoft.Build.Tasks.Core package didn't work for us either because it requires .NET 4.5+, and we target .NET 4.0. And the other suggestions simply disable the binding redirects which is dangerous as Mauro says. That could lead to very difficult to diagnose compilation errors down the track.

What ultimately ended up working for us was telling Jenkins to use a new version of MS Build. Instead of MS Build 4.0, we call the MS Build from VS 2013 or VS 2017 and it appears to have the GenerateBindingRedirects task available and builds fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.