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

Revisit .tlb generation with dscom #605

Open
govert opened this issue May 12, 2023 · 5 comments
Open

Revisit .tlb generation with dscom #605

govert opened this issue May 12, 2023 · 5 comments

Comments

@govert
Copy link
Member

govert commented May 12, 2023

This is partly an issue and partly documenting the current behaviour.

Our current approach to making a .tlb file with dscom is to require it to be installed as global tool.

Then a project targeting .net6.0-windows can have this property set:

    <ExcelAddInTlbCreate>true</ExcelAddInTlbCreate>

and everything works.

This does not build when targeting .NET Framework - we get an error

1>    MSBUILD : ExcelDnaBuild error DNA731704007: Cannot start process because a file name has not been provided.
1>    MSBUILD : ExcelDnaBuild error DNA731704007: System.InvalidOperationException: Cannot start process because a file name has not been provided.
1>    MSBUILD : ExcelDnaBuild error DNA731704007:    at System.Diagnostics.Process.Start()
1>    MSBUILD : ExcelDnaBuild error DNA731704007:    at ExcelDna.AddIn.Tasks.Utils.ProcessRunner.Run(String fileName, String arguments, String appName, IBuildLogger log)
1>    MSBUILD : ExcelDnaBuild error DNA731704007:    at ExcelDna.AddIn.Tasks.CreateExcelAddIn.TryCreateTlb()
1>    MSBUILD : ExcelDnaBuild error DNA731704007:    at ExcelDna.AddIn.Tasks.CreateExcelAddIn.Execute()

Q: I think DsCom can work when targeting .NET Framework too. Is enabling this (by fixing the problem above) perhaps a good alternative to using the TlbExe where we need to locate the path etc.

(We still want the TlbExp option, since it has some features that DsCom does not support.)

An alternative that does not require the global tool install is to use the DsCom package like this (without ExcelAddInTlbCreate)

<ItemGroup>
    <PackageReference Include="ExcelDna.Addin" Version="1.7.0-rc4" />
    <PackageReference Include="dSpace.Runtime.InteropServices.BuildTasks" Version="0.23.4" />
    <DsComTlbExportAssemblyPaths Include="$(NuGetPackageRoot)exceldna.integration/1.7.0-rc4/lib/net6.0-windows7.0" /> 
</ItemGroup>

I think this is good, and seems to work fine for both .NET Framework and .NET 6.

Q: Is there a better way to deal with the required path in DsComTlbExportAssemblyPaths (which we need so that ExcelDna.Integration.dll will be found by DsCom)? I'm also not sure whether the net6.0-windows vs net452 is important in the path here.

@govert
Copy link
Member Author

govert commented May 12, 2023

I was experimenting with this project https://github.com/govert/NewComServer

@Sergey-Vlasov
Copy link
Contributor

Sergey-Vlasov commented Jun 3, 2023

I've fixed dscom not building when targeting .NET Framework:
#614

Requires <ExcelDnaTlbDscom>true</ExcelDnaTlbDscom> in a project file.

@Sergey-Vlasov
Copy link
Contributor

I've added DsComTlbExportAssemblyPaths initialization from our build:
#615

With this change, there is no need to add it to a project file.

@govert
Copy link
Member Author

govert commented Sep 26, 2023

@Sergey-Vlasov There seems to be an issue when we use the DsCom build task.
The .tlb is generated correctly, but after the ExcelDnaPack task runs. So in a fresh build (when there is no output files yet), the packing does not include the .tlb. The .tlb is crteated after the packing using the dsCom task. When building again (with the .tlb present) it will be packed, but the .tlb might be out of date.

Could you have a look at how we can make the DsCom task "DsComExportTypeLibraryAfterBuild" run before we run "ExcelDnaPack", or run ExcelDnaPack again afterwards?

Here is an extract from my build log, when building the https://github.com/govert/NewComServer project with a clean output directory

1>Target ExcelDnaPack:
1>  Building target "ExcelDnaPack" completely.
1>  No input files were specified.
1>  Task "Message"
1>    ExcelDnaPack: bin\Debug\net6.0-windows\NewComServer-AddIn.dna -> bin\Debug\net6.0-windows\publish\NewComServer-AddIn-packed.xll
1>  Done executing task "Message".
1>  Using "PackExcelAddIn" task from assembly "C:\Users\GovertvanDrimmelen\.nuget\packages\exceldna.addin\1.7.0-rc6\build\..\tools\net452\ExcelDna.AddIn.Tasks.dll".
1>  Task "PackExcelAddIn"
1>    PackExcelAddIn: Running PackExcelAddIn Task
1>    PackExcelAddIn: Using base add-in bin\Debug\net6.0-windows\NewComServer-AddIn.xll
1>    PackExcelAddIn:   ~~> ExternalLibrary path NewComServer.dll resolved to bin\Debug\net6.0-windows\NewComServer.dll.
1>    Assembly loaded during TaskRun (ExcelDna.AddIn.Tasks.PackExcelAddIn): NewComServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null (location: , MVID: ed47adec-e75c-47b3-a188-6b385cf61d82, AppDomain: [Default])
1>    PackExcelAddIn:   ->  Updating resource: Type: DNA, Name: __MAIN__, Length: 574
1>    PackExcelAddIn:   ->  Updating resource: Type: ASSEMBLY_LZMA, Name: NEWCOMSERVER, Length: 4172
1>    PackExcelAddIn: Completed Packing bin\Debug\net6.0-windows\publish\NewComServer-AddIn-packed.xll.
1>  Done executing task "PackExcelAddIn".
1>  Task "Message" skipped, due to false condition; (Exists('%(ExcelDnaFilesToPack.OutputXllConfigFileName)')) was evaluated as (Exists('bin\Debug\net6.0-windows\NewComServer-AddIn.xll.config')).
1>  Task "Copy" skipped, due to false condition; (Exists('%(ExcelDnaFilesToPack.OutputXllConfigFileName)')) was evaluated as (Exists('bin\Debug\net6.0-windows\NewComServer-AddIn.xll.config')).
1>Target ExcelDnaPack:
1>  Building target "ExcelDnaPack" completely.
1>  No input files were specified.
1>  Task "Message"
1>    ExcelDnaPack: bin\Debug\net6.0-windows\NewComServer-AddIn64.dna -> bin\Debug\net6.0-windows\publish\NewComServer-AddIn64-packed.xll
1>  Done executing task "Message".
1>  Task "PackExcelAddIn"
1>    PackExcelAddIn: Running PackExcelAddIn Task
1>    PackExcelAddIn: Using base add-in bin\Debug\net6.0-windows\NewComServer-AddIn64.xll
1>    PackExcelAddIn:   ~~> ExternalLibrary path NewComServer.dll resolved to bin\Debug\net6.0-windows\NewComServer.dll.
1>    Assembly loaded during TaskRun (ExcelDna.AddIn.Tasks.PackExcelAddIn): NewComServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null (location: , MVID: ed47adec-e75c-47b3-a188-6b385cf61d82, AppDomain: [Default])
1>    PackExcelAddIn:   ->  Updating resource: Type: DNA, Name: __MAIN__, Length: 574
1>    PackExcelAddIn:   ->  Updating resource: Type: ASSEMBLY_LZMA, Name: NEWCOMSERVER, Length: 4172
1>    PackExcelAddIn: Completed Packing bin\Debug\net6.0-windows\publish\NewComServer-AddIn64-packed.xll.
1>  Done executing task "PackExcelAddIn".
1>  Task "Message" skipped, due to false condition; (Exists('%(ExcelDnaFilesToPack.OutputXllConfigFileName)')) was evaluated as (Exists('bin\Debug\net6.0-windows\NewComServer-AddIn64.xll.config')).
1>  Task "Copy" skipped, due to false condition; (Exists('%(ExcelDnaFilesToPack.OutputXllConfigFileName)')) was evaluated as (Exists('bin\Debug\net6.0-windows\NewComServer-AddIn64.xll.config')).
1>Target "GenerateBuildDependencyFile" skipped. Previously built successfully.
1>Target "GenerateBuildRuntimeConfigurationFiles" skipped. Previously built successfully.
1>Target CoreBuild:
1>Target AfterBuild:
1>Target ExcelDnaDscomIntegration:
1>Target DsComExportTypeLibraryAfterBuild:
1>  Building target "DsComExportTypeLibraryAfterBuild" completely.
1>  Output file "C:\Temp\NewComServer\bin\Debug\net6.0-windows\\NewComServer.tlb" does not exist.
1>  Task "Message"
1>    Calling dscom.exe to export type library
1>  Done executing task "Message".
1>  Task "Message"
1>    Using arguments '      tlbexport --asmpath "C:\Users\GovertvanDrimmelen\.nuget\packages\exceldna.addin\1.7.0-rc6\build\..\tools\net452"   C:\Temp\NewComServer\bin\Debug\net6.0-windows\NewComServer.dll  --out "C:\Temp\NewComServer\bin\Debug\net6.0-windows\\NewComServer.tlb"' to call dscom
1>  Done executing task "Message".
1>  Using "Exec" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
1>  Task "Exec"
1>    C:\Users\GovertvanDrimmelen\.nuget\packages\dspace.runtime.interopservices.buildtasks\1.2.0\build\..\tools\x64\dscom.exe       tlbexport --asmpath "C:\Users\GovertvanDrimmelen\.nuget\packages\exceldna.addin\1.7.0-rc6\build\..\tools\net452"   C:\Temp\NewComServer\bin\Debug\net6.0-windows\NewComServer.dll  --out "C:\Temp\NewComServer\bin\Debug\net6.0-windows\\NewComServer.tlb"
1>  Done executing task "Exec".
1>  Task "Warning" skipped, due to false condition; (!Exists('$(_DsComExportTypeLibraryTargetFile)')) was evaluated as (!Exists('C:\Temp\NewComServer\bin\Debug\net6.0-windows\\NewComServer.tlb')).
1>Target "DsComExportTypeLibraryAndRegisterAssembly" skipped, due to false condition; ('$(DsComRegisterTypeLibrariesAfterBuild)' == 'true') was evaluated as ('false' == 'true').
1>Target "ExcelDnaBuild" skipped. Previously built successfully.
1>Target "ExcelDnaPack" skipped. Previously built successfully.

@govert
Copy link
Member Author

govert commented Sep 26, 2023

This discussion initiated things, but there are some red herrings https://groups.google.com/g/exceldna/c/3tUc6WuT-xc

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

No branches or pull requests

2 participants