加载VSTA VB模板项目时出现异常 [英] Exception on loading VSTA VB template project

查看:97
本文介绍了加载VSTA VB模板项目时出现异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All



我想在我的几个项目中使用VSTA for VS2017。在开始使用我在Microsoft SDK文件夹中找到的文档VSTA Sample Host Integration.docx之前,我从来没有做过任何事情。我可以创建第一个C#应用程序并且它正在运行。我可以实现自己的函数和对象,到目前为止它看起来很好。文档中的所有示例都在C#中,但它也表示可以使用VB。计划是在我运行C#后切换到VB。我将所有内容翻译成VB并可以打开IDE,但加载项目会抛出System.Exception



Hello All

I would like to use VSTA for VS2017 for a couple of my projects. I have never done anything with it before I started with the document "VSTA Sample Host Integration.docx" which I found in the Microsoft SDK folder. I could create the first C# app and it's running. I could implement my own functions and objects and it looks good so far. All the examples in the documentation are in C#, but it says VB can be used as well. The plan was to switch to VB once I get C# to run.I translated everything to VB and can open the IDE, but loading the project is throwing a "System.Exception"

Imports Microsoft.VisualStudio.Tools.Applications
Imports System.IO
Imports System.Reflection




Private _session As Session
    Private _project As Project




Public Sub OpenIDE()
        If IsNothing(_session) = True Then

            Dim sessionMgr As SessionManager = SessionManager.Create("MyHostApp")

            _session = sessionMgr.CreateSession()

        End If

        _session.Ide.Show()
    End Sub







Public Sub NewVSTAProject()
        If (IsNothing(_session) = True) Or (IsNothing(_project) = False) Then
            'Error handling
            Exit Sub
        End If

        Dim storageCS As IProjectStorage = ProjectStorage.CreateStorageFromTemplate("templateCS.vstax", "csaddin", "VSTASampleCS", Nothing)
        Dim storageVB As IProjectStorage = ProjectStorage.CreateStorageFromTemplate("templateVB.vstax", "vbaddin", "VSTASampleVB", Nothing)

        
        _project = _session.LoadProject(storageVB)     <-----Exception
        _project = _session.LoadProject(storageCS)
       

    End Sub





我尝试了什么:



我使用的文档可以创建成功



- C#VSTA模板文件

-an打开IDE并在C中运行脚本的应用程序





我完成了文档中的所有步骤并将它们转换为VB。 TemplateProject中的GUID设置为VB。请参阅下面的项目文件。



TemplateProject.vbproj



What I have tried:

I used the documentation and could create successfully

-C# VSTA Template file
-an Application which opens the IDE and runs a script in C#


I did all the steps in the documentation and translated them to VB. The GUID in the TemplateProject is set to VB. Please see project files below.

TemplateProject.vbproj

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{$guid1$}</ProjectGuid>
    <OutputType>Library</OutputType>
    <RootNamespace>$safeprojectname$</RootNamespace>
    <AssemblyName>$safeprojectname$</AssemblyName>
    <FileAlignment>512</FileAlignment>
    <MyType>Windows</MyType>
    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
	<ProjectTypeGuids>{30D016F9-3734-4E33-A861-5E7D899E18F3};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}</ProjectTypeGuids>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <DefineDebug>true</DefineDebug>
    <DefineTrace>true</DefineTrace>
    <OutputPath>bin\Debug\</OutputPath>
    <DocumentationFile>$safeprojectname$.xml</DocumentationFile>
    <NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
    <ProjectTypeGuids>{30D016F9-3734-4E33-A861-5E7D899E18F3};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}</ProjectTypeGuids>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <DefineDebug>false</DefineDebug>
    <DefineTrace>true</DefineTrace>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DocumentationFile>$safeprojectname$.xml</DocumentationFile>
    <NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
    <ProjectTypeGuids>{30D016F9-3734-4E33-A861-5E7D899E18F3};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}</ProjectTypeGuids>
  </PropertyGroup>
  <PropertyGroup>
    <OptionExplicit>On</OptionExplicit>
  </PropertyGroup>
  <PropertyGroup>
    <OptionCompare>Binary</OptionCompare>
  </PropertyGroup>
  <PropertyGroup>
    <OptionStrict>Off</OptionStrict>
  </PropertyGroup>
  <PropertyGroup>
    <OptionInfer>On</OptionInfer>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="System.Net.Http" />
  </ItemGroup>
  <ItemGroup>
    <Import Include="Microsoft.VisualBasic" />
    <Import Include="System" />
    <Import Include="System.Collections" />
    <Import Include="System.Collections.Generic" />
    <Import Include="System.Data" />
    <Import Include="System.Diagnostics" />
    <Import Include="System.Linq" />
    <Import Include="System.Xml.Linq" />
    <Import Include="System.Threading.Tasks" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="AddIN.vb" />
    <Compile Include="My Project\AssemblyInfo.vb" />
    <Compile Include="My Project\Application.Designer.vb">
      <AutoGen>True</AutoGen>
      <DependentUpon>Application.myapp</DependentUpon>
    </Compile>
    <Compile Include="My Project\Resources.Designer.vb">
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>Resources.resx</DependentUpon>
    </Compile>
    <Compile Include="My Project\Settings.Designer.vb">
      <AutoGen>True</AutoGen>
      <DependentUpon>Settings.settings</DependentUpon>
      <DesignTimeSharedInput>True</DesignTimeSharedInput>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <EmbeddedResource Include="My Project\Resources.resx">
      <Generator>VbMyResourcesResXFileCodeGenerator</Generator>
      <LastGenOutput>Resources.Designer.vb</LastGenOutput>
      <CustomToolNamespace>My.Resources</CustomToolNamespace>
      <SubType>Designer</SubType>
    </EmbeddedResource>
  </ItemGroup>
  <ItemGroup>
    <None Include="My Project\Application.myapp">
      <Generator>MyApplicationCodeGenerator</Generator>
      <LastGenOutput>Application.Designer.vb</LastGenOutput>
    </None>
    <None Include="My Project\Settings.settings">
      <Generator>SettingsSingleFileGenerator</Generator>
      <CustomToolNamespace>My</CustomToolNamespace>
      <LastGenOutput>Settings.Designer.vb</LastGenOutput>
    </None>
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
  <ProjectExtensions>
    <VisualStudio>
      <FlavorProperties GUID="{30D016F9-3734-4E33-A861-5E7D899E18F3}">
        <ProjectProperties HostName="MyHostApp" HostPackage="{B3A685AA-7EAF-4BC6-9940-57959FA5AC07}" ApplicationType="" Language="vb" TemplatesPath="" />
      </FlavorProperties>
    </VisualStudio>
  </ProjectExtensions>
</Project>





manifestVB.xml



manifestVB.xml

<?xml version="1.0" encoding="utf-8" ?>
<VstaTemplates xmlns="http://schemas.microsoft.com/developer/vstatemplatemanifest/2011" TemplateVersion="1.0">
  <ProjectTemplate ProjectType="msBuild" TemplateName="vbaddin">
    <ProjectItems>
      <ProjectItem ReplaceParameters="true"

                   SourceFilePath="TemplateProjectVB\TemplateProject.vbproj"

                   TemplateFilePath="vbaddin\AddIn.vbproj"

                   TargetFilePath="$projectname$.csproj"

                   TargetItemType="Project" />

      <ProjectItem ReplaceParameters="true"

                   SourceFilePath="TemplateProjectVB\AddIn.vb"

                   TemplateFilePath="vbaddin\AddIn.vb"

                   TargetFilePath="AddIn.vb" />

      <ProjectItem ReplaceParameters="true"

                   SourceFilePath="TemplateProjectVB\My Project\AssemblyInfo.vb"

                   TemplateFilePath="vbaddin\AssemblyInfo.vb"

                   TargetFilePath="vbaddin\AssemblyInfo.vb" />
		<AutoGenProjectItem TargetFilePath="mygeneratedkeyfile.snk" AutoGenerate="StrongNameKeyFile" />
    </ProjectItems>
</ProjectTemplate>
</VstaTemplates>









AssemblyInfo.vb





AssemblyInfo.vb

Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices

' General Information about an assembly is controlled through the following
' set of attributes. Change these attribute values to modify the information
' associated with an assembly.

' Review the values of the assembly attributes

<Assembly: AssemblyTitle("$safeprojectname$")>
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("$safeprojectname$")>
<Assembly: AssemblyCopyright("")>
<Assembly: AssemblyTrademark("")>

<Assembly: ComVisible(False)>

'The following GUID is for the ID of the typelib if this project is exposed to COM
<Assembly: Guid("$guid2$")>

' Version information for an assembly consists of the following four values:
'
'      Major Version
'      Minor Version
'      Build Number
'      Revision
'
' You can specify all the values or you can default the Build and Revision Numbers
' by using the '*' as shown below:
' <Assembly: AssemblyVersion("1.0.*")>

<Assembly: AssemblyVersion("1.0.0.0")>
<Assembly: AssemblyFileVersion("1.0.0.0")>







I used the executable \"EnableVstaEventLogging.exe\" which is located in the SDK...Tools folder to activate additional output in the event viewer. It shows 2 warnings and 1 error, but I don’t know, what to do with it.



The 2 warnings






I used the executable "EnableVstaEventLogging.exe" which is located in the SDK...Tools folder to activate additional output in the event viewer. It shows 2 warnings and 1 error, but I don't know, what to do with it.

The 2 warnings

- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
  <Provider Name="VSTA" /> 
  <EventID Qualifiers="0">0</EventID> 
  <Level>3</Level> 
  <Task>0</Task> 
  <Keywords>0x80000000000000</Keywords> 
  <TimeCreated SystemTime="2018-03-07T21:48:29.000000000Z" /> 
  <EventRecordID>100</EventRecordID> 
  <Channel>VSTA Log</Channel> 
  <Computer>N7P179USB64BIT.de.cenit-group.com</Computer> 
  <Security /> 
  </System>
- <EventData>
  <Data>devenv(19600): Warning: System.Runtime.InteropServices.COMException (0x80004005): A project with that name is already opened in the solution. at EnvDTE.SolutionClass.AddFromFile(String FileName, Boolean Exclusive) at Microsoft.VisualStudio.Tools.Applications.Package.IdeWcfService.<>c__DisplayClass32_1.<AddProjectFromFile>b__0() at Microsoft.VisualStudio.Tools.Applications.Common.VstaCallbackBase.ExecuteAction(String id) 3/7/2018 1:48:29 PM</Data> 
  </EventData>
  </Event>







- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
  <Provider Name="VSTA" /> 
  <EventID Qualifiers="0">0</EventID> 
  <Level>3</Level> 
  <Task>0</Task> 
  <Keywords>0x80000000000000</Keywords> 
  <TimeCreated SystemTime="2018-03-07T21:48:29.000000000Z" /> 
  <EventRecordID>101</EventRecordID> 
  <Channel>VSTA Log</Channel> 
  <Computer>N7P179USB64BIT.de.cenit-group.com</Computer> 
  <Security /> 
  </System>
- <EventData>
  <Data>devenv(19600): Warning: System.Runtime.InteropServices.COMException (0x80004005): A project with that name is already opened in the solution. at Microsoft.VisualStudio.Tools.Applications.Common.VstaCallbackBase.InvokeOnMainThread(String name, Action action) at Microsoft.VisualStudio.Tools.Applications.Package.VstaPackage.InvokeOnMainThreadIfNeeded(String name, Action action) at Microsoft.VisualStudio.Tools.Applications.Package.IdeWcfService.AddProjectFromFile(String relativeProjectPath, String relativeSolutionPath, String solutionName, String codeFileExtension, Boolean returnReferencePathList, Boolean getPrjImports, String& rootDir, VstaIdeProjectItemInfo[]& initProjItemInfoList, String[]& referencePathList, String[]& importsList) 3/7/2018 1:48:29 PM</Data> 
  </EventData>
  </Event>





The error:



The error:

- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
  <Provider Name="VSTA" /> 
  <EventID Qualifiers="0">0</EventID> 
  <Level>2</Level> 
  <Task>0</Task> 
  <Keywords>0x80000000000000</Keywords> 
  <TimeCreated SystemTime="2018-03-07T21:48:29.000000000Z" /> 
  <EventRecordID>102</EventRecordID> 
  <Channel>VSTA Log</Channel> 
  <Computer>N7P179USB64BIT.de.cenit-group.com</Computer> 
  <Security /> 
  </System>
- <EventData>
  <Data>AutoFast(10220): Error: Microsoft.VisualStudio.Tools.Applications.IdeCommunications.IdeException: Exception of type 'Microsoft.VisualStudio.Tools.Applications.IdeCommunications.IdeException' was thrown. at Microsoft.VisualStudio.Tools.Applications.Common.VstaWcfProxyBase`2.CallService[LT](Func`1 func, Boolean ignoreCommunicationFailure) at Microsoft.VisualStudio.Tools.Applications.IdeCommunications.IdeProxy.AddProjectFromFile(String relativeProjectName, String relativeSolutionPath, String solutionName, String codeFileExtension, List`1 referencePathList, List`1 projectImportList, VstaIdeProjectItemInfo[]& initProjItemInfoList) at Microsoft.VisualStudio.Tools.Applications.IdeCommunications.IdeServer.AddProjectFromFile(String relativeProjectName, String relativeSolutionPath, String solutionName, String codeFileExtension, List`1 referencePathList, List`1 projectImportList, VstaIdeProjectItemInfo[]& initProjItemInfoList) at Microsoft.VisualStudio.Tools.Applications.IdeCommunications.IdeCommunicationsServer.Microsoft.VisualStudio.Tools.Applications.IdeCommunications.External.IIdeCommunications.OpenProject(IIdeProjectCallback ideProjectCallback, IDataStore dataStore) 3/7/2018 1:48:29 PM</Data> 
  </EventData>
  </Event>





The warning says, that there is a project with the same name, but I’m a bit lost. I checked the variable \"storageVB\" and it looks like, there GUIDs are replaced and they change, if I recompile.





Thank you very much for your help and reading this! If you need more information, please let me know.





Thank you!



Mark



The warning says, that there is a project with the same name, but I'm a bit lost. I checked the variable "storageVB" and it looks like, there GUIDs are replaced and they change, if I recompile.


Thank you very much for your help and reading this! If you need more information, please let me know.


Thank you!

Mark

推荐答案

(MSBuildExtensionsPath)\
(MSBuildExtensionsPath)\


(MSBuildToolsVersion)\Microsoft.Common.props\" Condition=\"Exists('
(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('


(MSBuildExtensionsPath)\
(MSBuildExtensionsPath)\


这篇关于加载VSTA VB模板项目时出现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆