Build/Test Issues

Problem building a project with custom BeforeBuild target

Started by hmemcpy on 10,796 views

Hi there!

I am using a trick I learned from @jfroma's blog, for automatically downloading missing nuget packages, so that I could keep the binaries out of the source control. This requires adding a custom BeforeBuild action in the csproj file:

<Target Name="BeforeBuild">
  <Exec Condition="Exists('$(ProjectDir)packages.config')"
          Command="&quot;$(SolutionDir)Tools\nuget.exe&quot; install &quot;$(ProjectDir)packages.config&quot; -o &quot;$(SolutionDir)Packages&quot;" />
</Target>


Unfortunately, it seems that NCrunch tries to execute this action even when I set in the configuration that Before/After build events for this projects should be disabled.
Since NCrunch copies the project to another location, the paths are no longer correct, and I get the following error:

(89): The command ""C:\Users\<my username>\AppData\Local\NCrunch\7872\280\tools\nuget.exe" install "C:\Users\<my username>\AppData\Local\NCrunch\7872\280\<my project>\packages.config" -o "C:\Users\<my username>\AppData\Local\NCrunch\7872\280\Packages"" exited with code 3.


I must temporary comment out the BeforeBuild target in my csproj file to make this work.

Please help :)

Thanks!
Hmm, just as a quick FYI, apparently this feature is now built into Nuget, and it's possible to achieve without doing this! Here are the details: http://blog.davidebbo.com/2011/08/easy-way-to-set-up-nuget-to-restore.html

Still, it'd be nice if NCrunch could really ignore custom beforebuild/afterbuild targets.

Thanks,
Igal.
Hi Igal,

Thanks for posting! The pre/post build event suppression at the moment only applies to the pre/post build event properties. To suppress the beforebuild/afterbuild targets, you simply need to apply an MSBuild condition to them, as such:

<Target Name="BeforeBuild" Condition="$(NCrunch) != '1'">
<Exec Condition="Exists('$(ProjectDir)packages.config')"
Command="&quot;$(SolutionDir)Tools\nuget.exe&quot; install &quot;$(ProjectDir)packages.config&quot; -o &quot;$(SolutionDir)Packages&quot;" />
</Target>
Oh sweet! I already switched to the more "standard" way of doing this (package restore), but good to know!

Thanks for the sweet product!

Post a reply

Log in to reply.