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

DsComTypeLibraryEmbedAfterBuild and _DsComExportTypeLibraryAssemblyFile #286

Closed
electro-logic opened this issue Oct 3, 2024 · 8 comments
Labels
limitation This is a known limitation

Comments

@electro-logic
Copy link

electro-logic commented Oct 3, 2024

Hi,
I'm trying the new EmbedTypeLibrary feature that sounds very promising.

My project has a BaseOutputPath to a custom directory and so I have in my project

< BaseOutputPath>D:</BaseOutputPath>
< _DsComExportTypeLibraryAssemblyFile>$(BaseOutputPath)</_DsComExportTypeLibraryAssemblyFile>

The problem is that dscom.exe is called with the right --tlbexport, but the wrong --embed parameter, pointing to the default OutputPath.

dscom.exe tlbexport "D:\x86\Release\net6.0\MyLibrary.dll" --embed C:\...\obj\x86\Release\net6.0\MyLibrary.comhost.dll --out "D:\x86\Release\net6.0\MyLibrary.tlb"" exited with code 1.

@marklechtermann
Copy link
Member

@bclothier can you take a look at this?

@bclothier
Copy link
Contributor

As I understand it, at this stage of the build, the .comhost.dll hasn't been yet copied to the output. That is why we use Microsoft's msbuild variable to get to the intermediate path:

<_DsComArguments Condition="'$(DsComTypeLibraryEmbedAfterBuild)' == 'true' AND $(ComHostIntermediatePath) != ''"> $(_DsComArguments) --embed $(ComHostIntermediatePath)</_DsComArguments>

Can you confirm that the file is present in the obj folder? If so, can you further verify that there is no errors embedding type library into the .comhost.dll by running the command manually.

@electro-logic
Copy link
Author

Hi, the file in the ComHostIntermediatePath (obj folder) is there and the .tlb is correctly embedded in the .dll (file is bigger). The problem is that the .dll is not copied back to the BaseOutputPath folder.

@bclothier
Copy link
Contributor

Hmm, the thing is that dscom does not control the building of the *.comhost.dll; this is done by Microsoft during the build. All dscom does is embedding the type library into the built *.comhost.dll which as I mentioned is located in the obj folder at that stage but at the end of the build, it should be then copied into the output directory, which is again done by Microsoft and not by dscom.

This does not explain why you would get exit code of 1. Do you see any detailed error in your build output log?

@electro-logic
Copy link
Author

Seems that I need to compile two times in row to get the .tlb embedded, can this be fixed?

@carstencodes
Copy link
Member

ComHostIntermediatePath is created in _CreateComHost in Microsoft.NET.Sdk.targets.

This is part of CompileDependsOn. CompileDependsOn must be executed before Compile.
Compile is part of CoreBuildDependsOn, which is executed before CoreBuild, which itself is part of BuildDependsOn.

DsComExportTypeLibraryAfterBuild is executed after AfterBuild.

So, in theory, the ComHostIntermediatePath must exist.

Unfortunately _CreateComHost depends on CoreCompile, which it itself is a dependency to.

So, if I see this correctly, building twice here is desired by .NET SDK ...

@marklechtermann marklechtermann added the limitation This is a known limitation label Nov 4, 2024
@marklechtermann marklechtermann closed this as not planned Won't fix, can't repro, duplicate, stale Nov 19, 2024
@electro-logic
Copy link
Author

I agree with closing this issue, but I think would be better to document this behavior somewhere

@marklechtermann
Copy link
Member

You are right! 👍
We will document this behavior by adding a limitation note in the README.md.

marklechtermann pushed a commit that referenced this issue Nov 19, 2024
Documents #286

Co-authored-by: Carsten Igel <cigel@dspace.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
limitation This is a known limitation
Projects
None yet
Development

No branches or pull requests

4 participants