defrancea / Projbook

Generate project documentation using Markdown and allow integrating code snippet from the source code being built. Code snippet are always up-to-date.
https://www.nuget.org/packages/Projbook
Other
15 stars 10 forks source link

v1.0.6 - Calling MSBuild from the command line fails generating the PDF #86

Closed robinbihun closed 8 years ago

robinbihun commented 8 years ago

For example we have build scripts that call msbuild in a build folder (not the same folder as our SLN file)

msbuild.exe src\solution.sln /t:Clean;Build /p:Configuration=Release;VisualStudioVersion=12.0

And when running this command I receive the following error on build of the ProjBook project:

...template.pdf.html : error : Error during PDF generation: Exception has been thrown by the target of an invocation.

If i remove the Projbook.targets file from the Projbook csproj file then i can build without errors, but that obviously defeats the purpose. I have not dug into the source any more to try and figure out why it might be failing, but i feel like it might be path issue...

defrancea commented 8 years ago

Very surprising. Is there any repository from where I can clone a project to repro? I would like to help on that but it's working fine here, at work and from mono. It's possible that it's a path issue but in this case I would like to improve the error message.

robinbihun commented 8 years ago

Yes, let me see if i can put together a sample that mimics what we're trying to do to see if we get the same error.

defrancea commented 8 years ago

Perfect, thanks.

robinbihun commented 8 years ago

I was able to replicate it with our folder structure -- hopefully a better error message will help us figure this out. https://github.com/robbihun/ProjBookScriptBuildError (running build\run-build.ps1 will replicate the error)

P.S. Sorry, i just realized i committed the packages folder :-/

defrancea commented 8 years ago

Sounds good, I'm going to have a look at it this week end and will let you know if I find something.

defrancea commented 8 years ago

I did try to reproduce but from VS and powershell I got no problem building it: projbookworking

You'll find a file at src\services\packages\Projbook.1.0.6\build\Projbook.props matching this content: https://github.com/defrancea/Projbook/blob/master/resources/Projbook.props Could you please replace $(MSBuildProjectFullPath) by the full path of the csproj file of your documentation project and see if it works? I think that the MSBuild version used from your script and from your Visual Studio are different and the MSBuild one doesn't populate any value in this variable. I can change this props file in order to have fallbacks to cover your case but we need to confirm that it's actually the problem first and find which variable we can use instead in your case.

robinbihun commented 8 years ago

I updated the Projbook.props file and receive the same error.

image

I also went a step further and updated the .targets file with all of the paths that should be what msbuild generates and get the same error. image

defrancea commented 8 years ago

Amazing, I got a repro. The problem appear when powerhsell runs as admin. I'm definitely going to address that, thanks a lot for noticing and reporting it. In the mean time what you ca do is:

defrancea commented 8 years ago

I was pretty busy with the 1.1 version and the plugin loading so I couldn't have a look at it until now. Very interesting bug, the actual error is: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

It comes from the underlying wkhtmltopdf dependency executing native dll. When it runs the first time it extracts the file wkhtmltox0.dll being the native one and keeps it for the next executions. In your case, visual studio have been previously executed extracting it for 64 bits. If you run poweshell as user (64) it keeps working, however when you run it as admin by default it runs as 32 bits, the dll is then incompatible and crash. You can do the test by removing the wkhtmltox0.dll file in packages/Projbook.1.0.6/tools and it will likery work from your admin powershell but will crash switching back to visual studio. As a fix, I can try to detect that this hapenned, wipe the file and retry during the build, it would make it transparent.

defrancea commented 8 years ago

Alright, so I just pushed an error message improvement (see right above). I tried to fix it silently but it will definitely lead to unpredictable behavior relating to file access hold by MSBuild. Also, because of https://github.com/defrancea/Projbook/issues/70, with 1.1 version you'll likely want to define the architecture you want to have the pdf generated on so it will be consistent across all builds. For your scenario, I advice you to simply run the script with the same architecture of the one you run your visual studio, it will make them compatible and everything should be alright. I'm closing the issue since everything has been figured out. Let me know if you need I release 1.0.7 now, but since it's just an error message I don't think it will be required. Thanks a lot for reporting that.