Skip to content

Fix for locating lib folder on netcore #1499

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

Closed

Conversation

dazinator
Copy link

This fixes #1498

@bording
Copy link
Member

bording commented Oct 25, 2017

As I've already mentioned, the lib folder isn't going to be around for .NET Core, so we'll need to come up with some other solution.

@dazinator
Copy link
Author

dazinator commented Oct 25, 2017

This is aimed to be a hotfix to enable msbuild tasks that leverage libgit2sharp to run under dotnet build, today.

Not trying to dictate / interfere with how you chose to address this longer term / in the future once /lib is removed.

@dazinator
Copy link
Author

dazinator commented Oct 25, 2017

If the decision is not to adopt this fix, I am happy to switch gitversion over to my own fork, until you have something in place perhaps? It's a bit of a pain but I guess that is the beauty of open source :-). It would mean publishing my temporary fork of libgit2sharp on nuget though - would you allow that?

@bording
Copy link
Member

bording commented Oct 25, 2017

The problem is that this isn't even a good enough temporary fix, because it won't work on non-windows platforms at all.

I think it makes sense to figure out to handle this MSBuild properly vs. temp fixes and forks.

@bording
Copy link
Member

bording commented Oct 25, 2017

Considering that Nerdbank.GitVersioning is working properly with .NET Core without needing changes makes me think the solution isn't to change LibGit2Sharp.

@dazinator
Copy link
Author

dazinator commented Oct 25, 2017

Nerdbank.Gitversioning works around this issue by adding significant plumbing code to its msbuild tasks for netcore. I would rather see the underyling issues fixed than complicate my msbuild task code. If its fixed it also means we dont need to compile for netcore we can compile for netstandard.

You can see all the workaround logic here: https://github.com/AArnott/Nerdbank.GitVersioning/blob/master/src/MSBuildExtensionTask/ContextAwareTask.cs

The fix I put in place fixes my issue on windows. You are right I did not also try to fix this for other platforms although I'm not sure - if I remoced the windows check, should my fix work on all platforms? It all depends on if assembly has CodeBase and Location available under other platforms.

If libgit2sharp exposed a way for the consumer to configure where it should look for its native assemblies that could be another way to solve this.

@dazinator
Copy link
Author

Not sure why the travis build failed.. Seems to be a problem with nuget restore. Don't think it's anything I have permissions to fix.

Always use Assembly.CodeBase and then Assembly.Location for native search path.
@dazinator
Copy link
Author

The problem is that this isn't even a good enough temporary fix, because it won't work on non-windows platforms at all.

I am closing this, as I think you are right. Fixing this for windows only is not a good enough solution.
If I need this fix for the interim period, I'll publish a temporary nuget package from my fork, which I will leave unlisted on nuget, and clearly named with my fork.

@dazinator dazinator closed this Oct 27, 2017
@bording
Copy link
Member

bording commented Oct 27, 2017

If libgit2sharp exposed a way for the consumer to configure where it should look for its native assemblies that could be another way to solve this.

FYI, a primary blocker from doing this is that the library search path can't be altered from within the process on unix like it can be from Windows. Once the process has been started, it's too late to alter it.

@dazinator
Copy link
Author

dazinator commented Oct 27, 2017

FYI, a primary blocker from doing this is that the library search path can't be altered from within the process on unix like it can be from Windows. Once the process has been started, it's too late to alter it.

Thanks for the info, that makes sense.

I think I have come to the conclusion that the only way to handle this for the msbuild task scenario, accross all platforms, is to have the msbuild task assembly loaded into, and executed from, a custom 'AssemblyLoadContext':
https://github.com/dotnet/coreclr/blob/master/Documentation/design-docs/assemblyloadcontext.md#pinvoke-resolution

Which can then implement that method to resolve native lib's locally to the task assembly.

I've raised an issue over on UtilPack: stazz/UtilPack#14 as I think it's something the msbuild task factory can take care of there.

@bording
Copy link
Member

bording commented Oct 27, 2017

I think I have come to the conclusion that the only way to handle this for the msbuild task scenario, accross all platforms, is to have the msbuild task assembly loaded into, and executed from, a custom 'AssemblyLoadContext':

That does appear to be how Nerdbank.GitVersioning has handled it: https://github.com/AArnott/Nerdbank.GitVersioning/blob/master/src/MSBuildExtensionTask/ContextAwareTask.cs#L72

@dazinator
Copy link
Author

Yup. I just feel strongly that putting this logic in the msbuild task itself is probably the wrong place. MsBuild tasks shouldn't have to be concerned with also being a proxy to themselves imho - they have enough to worry about. I also am not interested in compiling for netcore, I want to have a single compilation for netstandard! Huge respect to AArnott for the solution though - I am not dissing, just expressing my artistic licence :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MsBuild, Native binaries and AppContext.BaseDirectory.
2 participants