Kalle
Kalle

Reputation: 189

Is it possible to use a new SDK-style .csproj file for a VSTO Addin project

I cannot find any documentation, if VSTO AddIns are supported by SDK-style projects.

I already installed and used h. van brakels project2015to2017.migrate2019.tool. The resulting project files are usual class libraries and no more Powerpoint AddIns. Thus for example the projects cannot be startet anymore from the IDE for debugging.

The BootStrapperpackage and the ProjectExtension have not been transfered to the new file format. Additionally ProjectTypeGuids were not transfered. Maybe this marked the project as a VSTO Addin in the old style project files.

I'm frustrated I cannot find any statement if the SDK-style project files does support (and in this case how?) or does not support (and in this case why?) vsto addin projects! And furthermore, why does nobody dare to state/write that. It would make things clear and I don't have to waste my time searching for it ...

Thanks for your help, Karl

Upvotes: 9

Views: 816

Answers (2)

lauxjpn
lauxjpn

Reputation: 5254

Yes, it is possible to use sdk style project files with VSTO.

Explicitly import the Sdk.props and Sdk.targets files and import the Microsoft.VisualStudio.Tools.Office.targets file after the Sdk.targets file at the end.

Here is a sample .csproj file for an Excel document-level project:

<Project>
    <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
    <PropertyGroup>
        <TargetFramework>net48</TargetFramework>
        <Version>1.0.0</Version>
        <UseWindowsForms>true</UseWindowsForms>
    </PropertyGroup>
    <PropertyGroup>
        <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">17.0</VisualStudioVersion>
        <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
    </PropertyGroup>
    <PropertyGroup>
        <AssemblySearchPaths>$(AssemblySearchPaths);{GAC};$(VSToolsPath)\..\..\..\..\Common7\IDE\ReferenceAssemblies\v4.0</AssemblySearchPaths>
        <SolutionID>617d3c65-847f-4686-98de-dc8f19428505</SolutionID>
        <VSTO_HostDocumentName>MyDocument.xlsx</VSTO_HostDocumentName>
        <DefineConstants>VSTO40</DefineConstants>
        <OfficeApplication>Excel</OfficeApplication>
        <BootstrapperEnabled>true</BootstrapperEnabled>
        <BootstrapperComponentsLocation>HomeSite</BootstrapperComponentsLocation>
    </PropertyGroup>
    <PropertyGroup>
        <SignManifests>true</SignManifests>
        <ManifestKeyFile>MyDocument_TemporaryKey.pfx</ManifestKeyFile>
        <ManifestCertificateThumbprint>9A4030C742EF4F638078B084ECC76C118367C6BA</ManifestCertificateThumbprint>
    </PropertyGroup>
    <ItemGroup>
        <BootstrapperPackage Include="Microsoft.VSTORuntime.4.0">
            <Visible>False</Visible>
            <ProductName>Microsoft Visual Studio 2010 Tools for Office Runtime %28x86 and x64%29</ProductName>
            <Install>true</Install>
        </BootstrapperPackage>
    </ItemGroup>
    <ItemGroup>
        <Reference Include="Microsoft.Office.Interop.Excel">
            <EmbedInteropTypes>true</EmbedInteropTypes>
        </Reference>
        <Reference Include="Microsoft.Office.Tools.v4.0.Framework" />
        <Reference Include="Microsoft.VisualStudio.Tools.Applications.Runtime" />
        <Reference Include="Microsoft.Office.Tools" />
        <Reference Include="Microsoft.Office.Tools.Common" />
        <Reference Include="Microsoft.Office.Tools.Excel" />
        <Reference Include="Microsoft.Office.Tools.Common.v4.0.Utilities" />
        <Reference Include="Microsoft.Office.Tools.Excel.v4.0.Utilities" />
    </ItemGroup>
    <ItemGroup>
      <None Update="MyDocument.xlsx">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      </None>
    </ItemGroup>
    <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
    <Import Project="$(VSToolsPath)\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets" Condition="'$(VSToolsPath)' != ''" />
    <ProjectExtensions>
        <VisualStudio>
            <FlavorProperties GUID="{BAA0C2D2-18E2-41B9-852F-F413020CAA33}">
                <ProjectProperties HostName="MyDocument.xlsx" HostPackage="{3F2B7691-D1D1-402F-9370-2704A737CF60}" OfficeVersion="15.0" VstxVersion="4.0" ApplicationType="XLS" Language="CS" TemplatesPath="VSTOTemplates" DebugInfoExeName="C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE" DebugInfoCommandLine="/x &quot;[$OUTPUT]MyDocument.xlsx&quot;" />
                <Host Name="Excel Document" Path=".\MyDocument.xlsx" GeneratedCodeNamespace="MyDocument">
                    <HostItem Name="ThisWorkbook" Code="ThisWorkbook.cs" CanonicalName="ThisWorkbook" Blueprint="ThisWorkbook.Designer.xml" GeneratedCode="ThisWorkbook.Designer.cs" />
                    <HostItem Name="Sheet1" Code="MyDoc.cs" CanonicalName="Sheet1" DisplayName="MyDoc" Blueprint="MyDoc.Designer.xml" GeneratedCode="MyDoc.Designer.cs" />
                </Host>
            </FlavorProperties>
        </VisualStudio>
    </ProjectExtensions>
</Project>

Upvotes: 2

RobV8R
RobV8R

Reputation: 1076

To my knowledge, a VSTO project file cannot be converted to the newer SDK format. This is mostly because of the ProjectTypeGuids.

In order to properly convert a project file to the newer SDK format, there should be an SDK for the ProjectTypeGuids.

To my knowledge there is no VSTO SDK to use in the header of your project file.

[Edit]

MSBuild 15.0 introduced the concept of the "project SDK", which simplifies using software development kits that require properties and targets to be imported.

The information from the above link indicates that Project SDKs are the preferred successor to the "standard" MSBuild props and targets.

[Edit 2]

Have you considered the newer web based Add-In?

Upvotes: 2

Related Questions