3F / DllExport

.NET DllExport with .NET Core support (aka 3F/DllExport aka DllExport.bat)
MIT License
938 stars 131 forks source link

First time package restore - DllExport is not performed #159

Closed tapika closed 4 years ago

tapika commented 4 years ago

By briefly testing DllExport functionality - I've understood that integration into solution is not so standard mechanism - instead of nuget package restore project itself executes DllExport.bat -action Restore in $(SolutionDir)-directory.

During first restore + compilation however - the used dll becomes normal dll, without processing DllExport-attributes and it's not valid by itself. (This can be checked for example using Dependencies utility)

For second, etc problem disappears - as all required dll's from nuget package are downloaded and processed by Visual studio. This might require solution close / re-open step to make compilation process and intellisense fully functional.

I've tried to solve this, and removed from project

  <Target Name="DllExportRestorePkg" BeforeTargets="PrepareForBuild">

xml tag completely, but kept our own nuget package restore.

DllExport.bat besides restoring nuget package also generates some of dynamic dlls, which will come into DllExport.1.7.1\gcache, which are project specific dlls.

I've put into version control DllExport.1.7.1\gcache, also following files:

- tools\net.r_eg.DllExport.targets
- tools\RGiesecke.DllExport.dll
- tools\RGiesecke.DllExport.MSBuild.dll

Rest of files will be restored by nuget package restore functionality.

and after that even first compilation works correctly.

But with this fix - even first compilation start to work - I suspect msbuild is loading .dlls earlier than you expect - maybe needs to be fixed ?

3F commented 4 years ago

This might require solution close / re-open step to make compilation

This is only for old non Sdk-style projects. Modern VS environment processes everything at runtime (EnvDTE) due to construction through intermediate or obj files.

Well, I think I understood the problem.

In 2017 it was resolved as https://github.com/3F/DllExport/issues/62#issuecomment-353884634 And more like it was broken for new releases.

Can you check with latest 1.6.x release ? I will look into later. Thanks for the report!

Logically temp solution: execute -action Restore before build if no restored packages in folder.

3F commented 4 years ago

Confirmed. The problem because of unevaluated property $(DllExportMetaXBase) in the first phase. Broken in 1.7.

3F commented 4 years ago

@tapika Please confirm solution

DllExport -force -pkg-link https://ci.appveyor.com/api/buildjobs/8tg9w7gxpif8rb7l/artifacts/bin/Release/DllExport.1.7.1.nupkg

3F commented 4 years ago

https://github.com/3F/DllExport/pull/160#issuecomment-643430464

Planned for 1.7.3

tapika commented 4 years ago

Tested. Restore seems to be now working, but Visual studio intellisense on [DllExport] attribute starts to work only after you unload / re-load project. (Restore works thus)

But I guess to be able to restore DllExport - you need to cherry pick DllExport.bat into your own repository and save it there.

Btw, I have some multiple solutions, which are in different folders, which use same project. It would be better to use $(ProjectDir)..\<as many upper references as needed>\.. instead of $(SolutionDir) - otherwise saving / loading configuration always require manual modification.

Btw, if anyone wishes to use cmake for generating project, it's possible to use set_target_properties(project PROPERTIES VS_USER_PROPS .net.dllexport.targets)

but <PropertyGroup in first xml tag should not have condition. cmake in overall is bit difficult to configure what comes to custom xml tags.

3F commented 4 years ago

Tested. Restore seems to be now working, but Visual studio intellisense on [DllExport] attribute starts to work only after you unload / re-load project. (Restore works thus)

Please use modern Sdk-style. Then it will be auto re-loaded at runtime. Or consider click on reload button in VS File Modification Detected dialog for legacy project files (non-sdk based): https://youtu.be/okPThdWDZMM?t=96

But I guess to be able to restore DllExport - you need to cherry pick DllExport.bat into your own repository and save it there.

Yes, repo must contain at least DllExport.bat (~20 Kbytes) before build. But nothing else.

$(ProjectDir)..\..

I think you can try to open PR for providing some common solution with custom paths.

For cmake and related automation you can consider an available External storage + Export / Recover / https://github.com/3F/DllExport/wiki/DllExport-Manager#external-storage

Related issue: https://github.com/3F/DllExport/issues/76#issuecomment-396337025