Skip to content
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

Post-Build event no longer work as expected (if compared to UnmanagedExports) #35

Closed
OmegaExtern opened this issue May 4, 2017 · 5 comments
Labels
Milestone

Comments

@OmegaExtern
Copy link

I have discovered this bug a while ago and I am surprised to see that it is still not fixed.
Note: This bug is specific to DllExport code/package (any version)! Such bug does not exist in UnmanagedExports code/package (v1.2.7).

For example:

  1. Create a new C# class library project.
  2. Download/Install DllExport into project via NuGet (Install-Package DllExport, pick any version, the newest release v1.5.2 is still affected by this bug).
  3. Use whatever DllExport configuration options you want, it doesn't matter at all.
  4. Go to Project -> Properties -> Build Events page.
  5. Enter (or copy/paste) the following into post-build command line:
    COPY /Y "$(TargetPath)" "$(SolutionDir)$(TargetFileName)"

You should have something like this:
image
Next, build the project and wait for it to complete.
The above simple post-build event should copy the compiled DLL with exports into another directory (overwriting the existing file if it exists).
However, it seems that it instead copies compiled DLL without any exports into another directory.

And like I already said, this is not the case with UnmanagedExports package; post-build event works fine with UnmanagedExports package, apparently this bug has been introduced in DllExport code/package!

To speed things up, you can download my example (DllExport) VS2017 solution from here:
DllExport-PostBuild-issue.zip

And here you can also download another example VS2017 solution which uses UnmanagedExports package instead (to see that post-build works correctly with it):
UnmanagedExports-PostBuild.zip

Please fix DllExport :)

@3F
Copy link
Owner

3F commented May 5, 2017

I have discovered this bug a while ago and I am surprised to see that it is still not fixed.

Because of different environment, tools, etc. For example, often, I (especially) use vssbe scripts instead of this std. VS Build Events :)

But mainly I have no see any problems as you described for this issue. I mean this:

COPY /Y "$(TargetPath)" "$(SolutionDir)$(TargetFileName)"
TargetPath = <path to file>
TargetFileName = <our file>
SolutionDir = <path to directory>

I don't see any wildcards like ., *.exp, etc. from your demo projects, and I see expected result for simple command copy src dest - a single dll (without .exp & .lib) for both cases.

Please check your command, because it can be like this (as I understand for your case):

xcopy /Y "$(SolutionDir)$(ProjectName)\$(OutputPath)*.*" "$(SolutionDir)"

and similar...

since we are talking also about vssbe, same example:

#[IO copy.file("$(ProjectName)\$(OutputPath)*.*", "$(SolutionDir)", true)]

or like:

#[$(app = "$(SolutionDir)$(ProjectName)\$(OutputPath)")]
#[IO copy.file({
                    "$(app)*.dll",
                    "$(app)*.exp",
                    "$(app)*.lib"
                }, 
                "$(SolutionDir)", 
                true,
                { "$(app)*.pdb" })]

and other

So please review your problem again. And thanks for demo projects, because it always saves my time anyway :)

@OmegaExtern
Copy link
Author

OmegaExtern commented May 6, 2017

I don't see any wildcards like ., *.exp, etc. from your demo projects, and I see expected result for simple command copy src dest - a single dll (without .exp & .lib) for both cases.

I think you have misunderstood the issue here. You though of .exp/.obj generated files? Where did I mention those? Nowhere in above description have I mention anything about exp, obj, or wildcards, vssbe scripts, xcopy, etc. So obviously you misunderstood it, and the point is not to copy ALL files, just the compiled DLL (but that's less important).
The post-build command, in both Visual Studio solutions, if you have build them, then if you compare the destination assemblies of them, you would see that they are not the same, that is:
Destination UnmanagedExports.dll contains DLL exports (Method1 exists as expected).
Destination DllExport.dll does NOT contain any DLL exports (there is no Method1).

The main issue is that post-build event is not run at correct time with DllExport package, thus it copied DLL without any exports. Get it?


Edit:
Just to add to what I already said:
It doesn't matter, if I were to use xcopy, or vssbe scripts.. It would still again copy the DLL without any exports into another directory.
Because like I said a minute ago, the post-build event is run in wrong moment, and that's why destination DLL doesn't have any exports.
And to repeat it again: Post-Build command works correctly with UnmanagedExports package, which means that it is run in correct order and moment.

@3F
Copy link
Owner

3F commented May 6, 2017

You about records from IMAGE_DATA_DIRECTORY :)
I see, did not noticed because as I said above - it still all ok via vssbe scripts :)

for std. VS build-events I will look later, thanks.

temporarily you can try with vssbe, or try something manually via targets.

@3F 3F added the bug label May 6, 2017
@OmegaExtern
Copy link
Author

Here is the picture to clear it up:
image

@3F 3F added this to the v1.5.3 milestone Jun 3, 2017
3F added a commit that referenced this issue Jun 5, 2017
…#35

use this if still is needed:

```
<Target Name="PostBuildEventBeforeDllExport" BeforeTargets="DllExportMod">
   ...
</Target>
```
@3F
Copy link
Owner

3F commented Jun 5, 2017

please check it with latest changes - https://ci.appveyor.com/project/3Fs/dllexport/build/build-45/artifacts

But now we can't use Post-build events (PostBuildEvent) before processing our tool. If you need this, use something like:

<Target Name="PostBuildEventBeforeDllExport" BeforeTargets="DllExportMod">
  <Exec Command="..." ContinueOnError="true" />
</Target>

etc.

@3F 3F closed this as completed Jun 13, 2017
3F added a commit that referenced this issue Aug 12, 2017
* NEW: The new lightweight manager & distribution via MvsSln & GetNuTool projects. Issue #38.
       Based on hMSBuild logic and includes GetNuTool core.

       Now you shouldn't use standard nuget clients anymore:
       https://www.youtube.com/watch?v=okPThdWDZMM

       Package from nuget.org already contains this, but you can also get it directly.
       Latest version: https://raw.githubusercontent.com/3F/DllExport/latest/manager/DllExport.bat
       ~18 Kb text-based embeddable batch-scripts that does not require powershell and dotnet-cli.

       To install/uninstall or to reconfigure your projects: `DllExport -action Configure`
       To manually restore package: `DllExport -action Restore`
       All available features: `DllExport -h`

       Server by default - nuget.org

* NEW: The new Wizard (configurator via MvsSln). To easy configure your projects in any place. Issue #38.
       MvsSln v1.0.1.43422: https://github.com/3F/MvsSln

* NEW: Added support of global namespaces - Issue #47.
       Use `Direct-Mod` if Cecil will not process this correctly.

* FIXED: Fixed target platform detection. Issue #34.
         Details: #34 (comment)

* FIXED: Fixed problem when the Post-Build event is triggered before our tool. Issue #35.
         Use this if still is needed:
         ```
         <Target Name="PostBuildEventBeforeDllExport" BeforeTargets="DllExportMod">
            ...
         </Target>
         ```

* FIXED: Fixed generation of exp + .lib via MS Library Manager for VS2017. Issue #37.
         Now it also includes processing through VsDevCmd & VcVarsAll initializer scripts.
         Use the folowing msbuild properties to override values by default:
         * $(DllExportVcVarsAll); $(DllExportVsDevCmd)

* FIXED: Fixes possible problem with multiple properties that contains *Undefined* word,
         e.g.: *Undefined*\path1;C:\path2 ...

* CHANGED: Added information about finding lib tool. Issue #44.
* CHANGED: UI. Selected platform now affects to all configurations of project instead of active as before.
* CHANGED: Now, nuget package does not contain library in `lib/.../` Details in #36.
* CHANGED: Now, we also distribute .zip package for work through our manager etc.
           https://github.com/3F/DllExport/releases

           The latest text-based manager you can find here:
           https://raw.githubusercontent.com/3F/DllExport/latest/manager/DllExport.bat
           Illustration here: https://www.youtube.com/watch?v=okPThdWDZMM
3F added a commit that referenced this issue Dec 29, 2017
* NEW: The new embeddable lightweight manager for distribution via MvsSln & GetNuTool projects. Issue #38.
       Based on hMSBuild logic and includes GetNuTool core v1.6.1.

       Now you shouldn't use standard nuget clients anymore:
       https://www.youtube.com/watch?v=9bYgywZ9pPE

       Quick start: https://www.youtube.com/watch?v=sBWt-KdQtoc
        ==============================
        DllExport -action Configure
        ==============================

       Package from nuget.org already contains manager, but you can also get it directly.
       Latest manager: https://3F.github.io/DllExport/releases/latest/manager/
       ~18 Kb text-based embeddable batch-script that does not require powershell and dotnet-cli.

       Automatic restoring still is available but you can also use: `DllExport -action Restore`
       All available features: `DllExport -h`

       Direct links to remote package (without nuget server) via `-pkg-link {uri}` key. Issue #53.
       NuGet Server by default: nuget.org.

* NEW: The new Wizard (configurator via MvsSln). To easy configure your projects in any place. Part of Issue #38.
       MvsSln v2.0: https://github.com/3F/MvsSln

* NEW: Added support of empty/global namespaces - Issue #47.
       Use `Direct-Mod` if Cecil will not process this correctly.

* NEW: Implemented another storage for configuration: '.net.dllexport.targets'. Issue #49.

* NEW: New settings for configurator (Wizard):
        * Path to custom ILAsm.
        * Flag to keep intermediate Files (IL Code, Resources, ...).
        * Timeout of execution in milliseconds.

* NEW: Implemented automatic checking existence of a correct exported proc via Conari. Issue #55.
       Wizard controls it via `$(DllExportPeCheck)`:
        * 0x01 bit - Will check count of all planned exports from final PE32/PE32+ module.
        * 0x02 bit - Will check existence of all planned exports (IL code) in actual PE32/PE32+ module.

* NEW: Implemented PE32/PE32+ Viewer to check manually available exports from final modules. Issue #55.
       New key for manager:
        ```
        -pe-exp-list {module} - To list all available exports from PE32/PE32+ module.
        ```

        Sample:
        ```
        DllExport -pe-exp-list bin\Debug\regXwild.dll
        ```

* FIXED: Fixed target platform detection. Issue #34.
         Details: #34 (comment)

* FIXED: Fixed problem when the Post-Build event is triggered before our tool. Issue #35.
         Use this if still is needed:
         ```
         <Target Name="PostBuildEventBeforeDllExport" BeforeTargets="DllExportMod">
            ...
         </Target>
         ```

* FIXED: Fixed generation of exp + .lib via MS Library Manager for VS2017. Issue #37.
         Now it also includes processing through VsDevCmd & VcVarsAll initializer scripts.
         Use the folowing msbuild properties to override values by default:
         * $(DllExportVcVarsAll); $(DllExportVsDevCmd)

* FIXED: Fixes possible problem with multiple properties that contains *Undefined* word,
         e.g.: *Undefined*\path1;C:\path2 ...

* CHANGED: Added information about finding lib tool. Issue #44.

* CHANGED: UI. Selected platform now affects to all configurations of project instead of active as before.

* CHANGED: Now nuget package does not contain library in `lib/.../` Details in #36.

* CHANGED: Now we also distribute .zip package for work through our manager etc.
           https://github.com/3F/DllExport/releases

* NOTE: How to avoid EXP0014: RunIlAsm. The library manager still cannot be found.
        https://www.youtube.com/watch?v=zUejJ4vUPGw
        Related Issue #44

* NOTE: Quick start (Configuring, Automatic restoring, Pe-Viewer):
        https://www.youtube.com/watch?v=sBWt-KdQtoc

* NOTE: The latest text-based manager:
        https://3F.github.io/DllExport/releases/latest/manager/

           Other versions you can find from GitHub Releases:
           * https://github.com/3F/DllExport/releases

           Or get it from nuget packages starting with v1.6+

* NOTE: PE-features via Conari v1.3.0 https://github.com/3F/Conari

* KNOWN: Bug when - "Build successful but methods are not exported." Issue #59
         For today, anyone else may also try to use https://github.com/3F/Conari to avoid similar @Genteure's problem.

* DIFF(v1.6-RC):

    * FIXED: Wizard. Fixed incorrect layout for zh_CN Simplified Chinese (Thanks @Genteure). Issue #61
    * FIXED: Fixes automatic restoring the package via msbuild. Issue #62
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants