Microsoft.Office.Interop.Excel behaviour change after migrating from packages.config to PackageReference #11664
Unanswered
JeremiCurie
asked this question in
Q&A
Replies: 1 comment 1 reply
-
EmbedInteropTypes metadata is not automatically set for assembly references that come from PackageReference. That then causes worksheet.Cells[1, 2] to return object rather than dynamic. According to #2365, the package should include a targets file that sets the metadata, if the author of the package thinks the types should be embedded. If the package lacks that, you can add a similar target in your project or in Directory.Build.targets. https://github.com/NuGet/Samples/blob/d185393502edf11f6ceecdae319a7d7c19b30eca/NuGet.Samples.Interop/NuGet.Samples.Interop.targets <Target Name="EmbedExcelInterop" AfterTargets="ResolveReferences" BeforeTargets="FindReferenceAssembliesForReferences">
<ItemGroup>
<ReferencePath Condition="%(ReferencePath.NuGetPackageId) == 'Microsoft.Office.Interop.Excel'">
<EmbedInteropTypes>true</EmbedInteropTypes>
</ReferencePath>
</ItemGroup>
</Target> |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
After migrating from packages.config to PackageReference in a solution, I have an error when using the object "Value" of a cell in an Excel file :
example, when using this :
String test = (String)worksheet.Cells[1, 2].Value;
I get the following error :
error code : CS1061
error description : 'object' does not contain a definition for 'Value' and no accessible extension method 'Value' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
I know I could rollback but I'd like to understand what's wrong after migration ?
thanks for your help.
Jérémi.
Beta Was this translation helpful? Give feedback.
All reactions