|
-
Nov 22nd, 2016, 11:27 AM
#1
Change "Embed Interop Types" for a reference from a compiler directive?
Hey all,
I'm building an application that uses the MS Excel 15.0 Object Libraries and I want to embed them for a release configuration, but not for debugging. If they are embedded, edit and continue breaks which makes it a PITA.
I'm just curious is someone know how to use a compiler directive to change the embedding of the reference.
Code:
#If CONFIG = "Debug"
'don't embed the reference
#Else
'embed the reference
#End If
Based on my limited knowledge of linkers and complires, it doesn't seem like that is possible, but maybe a different way using the VS configuration?
thanks for your time
kevin
Last edited by kebo; Nov 22nd, 2016 at 12:02 PM.
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Nov 22nd, 2016, 12:56 PM
#2
Re: Change "Embed Interop Types" for a reference from a compiler directive?
As far as I know there is no why to do this with compiler directives embedded in the code files.
However, you can edit the MS Build file (projname.vbproj) to add such a condition. The only issue that I have observed is that the referenced file in the Solution Explorer pulls its properties from the first set of properties defined in the MS Build File; i.e. it does not acknowledge the condition set. For most cases, this is not an issue. But be warned that if say the first set of directives is for the Release condition and you change to the Debug build in VS and subsequently modify the referenced filer properties; those properties will be written to the first set (Release) in the MS Build file. I hope that made sense.
The gist of this is set up your project and save. Close the solution. Edit the MS Build file with your conditions (File-Open->File->select projname.vbproj). Make a backup of the new file. Close the file and reopen your solution and ignore what the property grid properties state as you change the selected build configuration in VS as it may or may not reflect the selected build configuration. However, the proper section is used when you build/run/debug your code.
This is all based on my observations using VS2013.
Now for the MS Build stuff.
Code:
<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<COMReference Include="Microsoft.Office.Core">
<Guid>{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}</Guid>
<VersionMajor>2</VersionMajor>
<VersionMinor>4</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
<COMReference Include="Microsoft.Office.Interop.Excel">
<Guid>{00020813-0000-0000-C000-000000000046}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>6</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
<COMReference Include="VBIDE">
<Guid>{0002E157-0000-0000-C000-000000000046}</Guid>
<VersionMajor>5</VersionMajor>
<VersionMinor>3</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
Code:
<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<COMReference Include="Microsoft.Office.Core">
<Guid>{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}</Guid>
<VersionMajor>2</VersionMajor>
<VersionMinor>4</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>False</EmbedInteropTypes>
</COMReference>
<COMReference Include="Microsoft.Office.Interop.Excel">
<Guid>{00020813-0000-0000-C000-000000000046}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>6</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>False</EmbedInteropTypes>
</COMReference>
<COMReference Include="VBIDE">
<Guid>{0002E157-0000-0000-C000-000000000046}</Guid>
<VersionMajor>5</VersionMajor>
<VersionMinor>3</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<EmbedInteropTypes>False</EmbedInteropTypes>
</COMReference>
</ItemGroup>
Note the emboldened first line declaring the ItemGroup with its condition. You can copy the condition clause from the PropertyGroup tags that define your build configurations. These are located at the beginning of the MSBuild file the VS creates for you project.
Code:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
<OutputPath>bin\Debug\</OutputPath>
<DocumentationFile>Test Embed Interop.xml</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<DefineDebug>false</DefineDebug>
<DefineTrace>true</DefineTrace>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DocumentationFile>Test Embed Interop.xml</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
</PropertyGroup>
-
Nov 22nd, 2016, 01:04 PM
#3
Re: Change "Embed Interop Types" for a reference from a compiler directive?
ok man, I don't where you pull this stuff from, but if it works I will be deeply grateful. I really don't want to disable the edit and continue, but I know eventually I'll forget to set the embedding before a release, so this will be quite helpful. It will be a little while until I test this, but I'll post back after I do.
kevin
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|