Office VSTO项目执行MSBuild -t:publish发布失败求助
Office VSTO项目MSBuild命令行发布失败解决方案
问题概述
- 项目可通过MSBuild.exe正常完成Debug、Release构建,但执行
MSBuild -t:publish命令时发布失败 - Visual Studio 2019社区版发布向导可正常生成包含.vsto文件、依赖引用目录及setup.exe的publish目录
- 命令行执行后报错:
Project "D:\repositories\myapp\myapp.sln" (1) is building "D:\repositories\myapp\myapp.csproj" (2) on node 1 (Publish target(s)). _DeploymentUnpublishable: Skipping unpublishable project.
已尝试无效操作
- 关闭杀毒软件
- 添加
/p:DeployOnBuild=true参数 - 尝试
/t:Package目标(触发MSB4057错误) - 向.csproj添加
<OutputType>winexe</OutputType> - 确认相关工具已安装,排除共享加载项场景
- 尝试创建.pubxml配置但未成功
可行解决方案
1. 引用VS生成的发布配置文件
如果已通过VS发布向导成功发布过,项目目录下的Properties\PublishProfiles会存在对应的.pubxml文件,执行以下命令:
MSBuild "D:\repositories\myapp\myapp.csproj" /t:Publish /p:PublishProfile=Properties\PublishProfiles\FolderProfile.pubxml /p:Configuration=Release
将FolderProfile.pubxml替换为实际的发布配置文件名。
2. 手动配置.csproj发布属性
若没有.pubxml文件,在.csproj的<PropertyGroup>节点内添加以下配置:
<PropertyGroup> <PublishDir>bin\Release\Publish\</PublishDir> <InstallUrl>file:///D:\repositories\myapp\bin\Release\Publish\</InstallUrl> <UpdateEnabled>true</UpdateEnabled> <UpdateMode>Foreground</UpdateMode> <ProductName>你的VSTO加载项名称</ProductName> <PublisherName>发布者名称</PublisherName> <MinimumRequiredVersion>1.0.0.0</MinimumRequiredVersion> <BootstrapperEnabled>true</BootstrapperEnabled> <GenerateManifests>true</GenerateManifests> <ApplicationVersion>1.0.0.0</ApplicationVersion> </PropertyGroup>
然后执行命令:
MSBuild "D:\repositories\myapp\myapp.csproj" /t:Publish /p:Configuration=Release /p:DeployOnBuild=true /p:PublishDir=bin\Release\Publish\
3. 确认VSTO项目目标导入
检查.csproj文件是否包含VSTO专用的目标导入语句(VS2019对应v16.0):
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v16.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v16.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets')" />
若缺失则添加,确保MSBuild能识别VSTO项目的发布逻辑。
4. 调用VSTO专用发布目标
直接执行VSTO项目专属的发布目标命令:
MSBuild "D:\repositories\myapp\myapp.csproj" /t:OfficePublish /p:Configuration=Release /p:PublishDir=bin\Release\Publish\
验证
执行命令后,查看指定的PublishDir目录,确认生成.vsto文件、依赖目录及setup.exe。
内容的提问来源于stack exchange,提问作者user20063348
相关产品推荐
相关产品推荐

