Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Post Build Event Failing
Martin Evans
#1 Posted : Sunday, June 2, 2013 1:37:50 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 11/29/2012(UTC)
Posts: 6
Location: United Kingdom

Thanks: 2 times
I've built a solution with three projects, using libgit2sharp. The solutions are:

1. A class library, referencing libgit2sharp (with a post build event, which copies the native git binaries into the build directory).
2. A console project, which calls a method in the class library.
3. A test project, which calls the same method.

Obviously this setup is analogous to a real situation, where I have a class library (which internally uses libgit2sharp) and an actual project which uses this library.

When I run the console project, and when I run the tests with the built in Visual Studio test runner everything is fine. However when I run the tests they fail with this message:

Quote:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets (4291)#0: The command "
if not exist "R:\8556\25\GitClassLibrary\bin\Debug\NativeBinaries" md "R:\8556\25\GitClassLibrary\bin\Debug\NativeBinaries"
if not exist "R:\8556\25\GitClassLibrary\bin\Debug\NativeBinaries\x86" md "R:\8556\25\GitClassLibrary\bin\Debug\NativeBinaries\x86"
xcopy /s /y "R:\8556\25\packages\LibGit2Sharp.0.11.0.0\NativeBinaries\x86\*.*" "R:\8556\25\GitClassLibrary\bin\Debug\NativeBinaries\x86"
if not exist "R:\8556\25\GitClassLibrary\bin\Debug\NativeBinaries\amd64" md "R:\8556\25\GitClassLibrary\bin\Debug\NativeBinaries\amd64"
xcopy /s /y "R:\8556\25\packages\LibGit2Sharp.0.11.0.0\NativeBinaries\amd64\*.*" "R:\8556\25\GitClassLibrary\bin\Debug\NativeBinaries\amd64"" exited with code 4.


I'm not too familiar with post-build events, so I'm not too sure what this is about. But it's definitely something NCrunch is doing that neither a vanilla run or the VS test runner do.
Remco
#2 Posted : Sunday, June 2, 2013 10:41:13 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,988

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi, thanks for posting!

My first thought is that the post build event is trying to copy files that don't exist in the NCrunch workspace. This is most likely because the files aren't referenced in a way that NCrunch is automatically aware of them. Try adding the following value to your additional files to include configuration setting for this project:

..\packages\**.*

Does this do the trick?


Cheers,

Remco
1 user thanked Remco for this useful post.
Martin Evans on 6/2/2013(UTC)
Martin Evans
#3 Posted : Sunday, June 2, 2013 11:35:00 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 11/29/2012(UTC)
Posts: 6
Location: United Kingdom

Thanks: 2 times
Aha, that fixed the post build event outright failing. But now I get a "System.DllNotFoundException" - i.e. the post build event hasn't properly put the files into a place where they could be found by libgit2sharp.
Remco
#4 Posted : Monday, June 3, 2013 3:57:44 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,988

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Great, that's progress! I'm wondering if the DllNotFoundException is being caused by libgit2sharp making assembly colocation assumptions. A quick fix to this may be to turn on the copy referenced assemblies to workspace configuration setting.

Is this exception being thrown during test execution? It may be worth right-clicking on the project in the Tests Window, and going to "Advanced->Browse to workspace" if you'd like to compare NCrunch workspace files with those in your normal working solution. This is often a quick and easy way to examine whether every file is where it should be.
Martin Evans
#5 Posted : Tuesday, June 4, 2013 12:13:37 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 11/29/2012(UTC)
Posts: 6
Location: United Kingdom

Thanks: 2 times
I tried copying assemblies to the workspace, this made no difference.

Browsing to the workspace shows me that in the bin folder for the TestProject is TestProject1.dll and TestProject1.pdb, so it looks like the NativeBinaries folder hasn't been copied across.
Remco
#6 Posted : Tuesday, June 4, 2013 9:22:56 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,988

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
My guess at the moment is that the post build event is copying the files to the build output directory of GitClassLibrary, although either the test code or the code under test is trying to find the files in the build output directory of TestProject. When running the tests outside of NCrunch, both of these output directories will likely be the same, but in the NCrunch test environment, they are different. The 'Copy referenced assemblies to workspace' option will automatically copy GitClassLibrary into the TestProject output directory, but it won't know about the NativeBinaries directory and thus won't copy it.

Is it possible to also set up the post build event so it will work on TestProject?

Just noting earlier you mentioned that this was a test solution you're working with. If it's something you can share, feel free to submit it to me through the contact form and I'll see if I can find a way to make it work.
Martin Evans
#7 Posted : Tuesday, June 4, 2013 1:41:22 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 11/29/2012(UTC)
Posts: 6
Location: United Kingdom

Thanks: 2 times
I added the post build event to the test project as you suggested, now I end up with a NativeBinaries directory, as expected, in the TestProject1/bin directory. However, the test still fails with a DLL not found exception. My guess is libgit2sharp relies on the working directory being set to the build directory which I suspect isn't how NCrunch sets it up?

The test solution is uploading via the contact form right now.
Remco
#8 Posted : Wednesday, June 5, 2013 1:26:48 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,988

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi Martin,

Thanks for sending through the sample solution. I've managed to get this to work by turning on the 'Copy referenced assemblies to workspace' option for ALL the projects in the solution. It looks as though the issue was that ALL dependencies needed to exist in the build output directory of the test project, and the nested dependencies weren't all being copied without the configuration setting being applied to everything.

The reliance on this configuration setting is unfortunate as it will create more build work for NCrunch while you are coding. Sadly, it look as though the assumptions around assembly referencing are coded into Libgit2sharp itself, so there may not be any other way to make this work without changing the library.

Cheers,

Remco
1 user thanked Remco for this useful post.
Martin Evans on 6/5/2013(UTC)
Martin Evans
#9 Posted : Wednesday, June 5, 2013 2:38:03 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 11/29/2012(UTC)
Posts: 6
Location: United Kingdom

Thanks: 2 times
Thanks very much for the help Remco.

Do you have any recommendations for how libgit2sharp could be changed to fix this? If you do then I may create an issue on the github and link this thread :)
Remco
#10 Posted : Wednesday, June 5, 2013 11:18:26 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,988

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
It's tough to give concrete advice without delving into the source code, but generally you should try to avoid loading assemblies into the application domain dynamically from the current directory. Instead, it may be better if there was a way to configure the search path for the native binaries (which are effectively resource files). As the developer integrating with libgit2sharp, you would have knowledge of where these resources are stored and which project they are primarily related to - allowing you to better control the loading behaviour by injecting a path relative to the location of your primary project (perhaps by using GetType().Assembly.Location).
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.065 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download