VSIX Flavored 项目自定义 .target 文件导入问题

发布于 2024-11-19 09:20:52 字数 547 浏览 3 评论 0原文

我有一个 VSIX 包,其中有几个基于 XML 的自定义设计器。这个包有一个风格化的项目系统,我在其中使用一些自定义构建任务在构建时自动生成代码。

我必须面对的第一个挑战是在我的项目模板中导入 .targets 文件。我无法在项目模板中提供 .targets 文件的完全限定路径,因为我的软件包版本发生了变化,这使得 vsix 安装程序将其放入目标计算机上的版本控制位置。我可以解决的方法是添加带有包根路径的用户环境变量,然后在项目模板中引用此环境变量以导入 .targets 文件。它按预期工作,但有一个警告。

现在需要注意的是如何在 VSIX 部署过程中创建此环境变量。我尝试使用从 RegistrationAttribute 派生的自定义属性来装饰包类。我重写了 Register 方法来运行 Environment.SetEnvironmentVariable() 并且它仅在我在开发盒上运行项目时才有效。显然,VSIXInstall.exe 不关心在安装过程中运行属性寄存器。

如果有人能提出解决此问题的方法,那就太好了。我的时间不多了,已经尝试了很多事情但没有成功:(

I have a VSIX package with couple of custom designers over XML. This package has a flavored project system in which I use some custom build tasks to auto generate code at build time.

First challenge I had to face was with importing .targets files in my project template. I cannot give a fully qualified path to the .targets file in the project template because my package version changes and that makes the vsix installer to drop it inside a version-ed location on the target machine. The way I could solve was to add a user environment variable with package root path and then refer this environment variable in the project template to import .targets file. It works as expected with a caveat.

Now the caveat is how I can create this environment variable during the VSIX deployment process. I tried decorating the package class with a custom attribute derived from RegistrationAttribute. I overrode the Register method to run Environment.SetEnvironmentVariable() and it only works when I run the project on my dev box. Apparently, VSIXInstall.exe does not care about running the attribute register during the install.

It will be great if somebody can suggest an approach to solve this issue. I am running out of time and already tried so many things without any success :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不喜欢何必死缠烂打 2024-11-26 09:20:52

[包括我之前通过电子邮件对同一问题的回复。]

Visual Studio 2010 不支持通过 VSIX 分发的 MSBuild 目标/任务。建议您使用 MSI(或类似的部署技术)并将目标文件拖放到您在 %ProgramFiles%\MSBuild 下选择的目录。然后,您可以通过 $(MSBuildExtensionsPath) 在项目模板中引用它们。

VSIX 安装本质上只是 VSIX 的“解压缩”。就是这样。无法注册或执行任何自定义操作。正如您所提到的,在构建时,会运行一个名为 CreatePkgDef.exe 的工具(它会加载程序集并调用 RegistrationAttribute)来创建 VSIX 中包含的 pkgdef 文件。

我认为您需要执行以下操作之一:

  1. 放弃 VSIX 并使用 MSI 进行部署(推荐方法)
  2. 将自定义目标包含在项目模板中。这很糟糕,因为现在目标分散在项目中,而不是安装到单个位置,但这对您来说可能是一个可以接受的解决方案。
  3. 在 VS 中“首次启动”包/扩展时进行一些初始化(例如设置环境变量)。当然,这意味着用户必须知道这是必要的安装后步骤。

我意识到这些解决方案都不是理想的。请注意,VSIX 提供更好的 MSBuild 支持是我们最需要的功能,因此我们确实收到了反馈。

[Including my previous reply to this same question asked over email.]

MSBuild targets/tasks distributed via VSIX are not supported in Visual Studio 2010. The recommendation is for you to use MSI (or similar deployment technology) and drop your targets files to a directory of your choosing under %ProgramFiles%\MSBuild. You can then refer to them in your project templates via $(MSBuildExtensionsPath).

VSIX installation is essentially just an “unzip” of your VSIX. That’s it. There’s no registration or ability to do custom actions whatsoever. As you alluded to, at build time, a tool called CreatePkgDef.exe runs (which is what loads your assembly and calls your RegistrationAttribute) to create the pkgdef file which is included in your VSIX.

I think you’ll need to do one of the following:

  1. Abandon VSIX and use MSI for deployment (the recommended approach)
  2. Include the custom targets in the project template. This is bad because now the targets are scattered amongst projects instead of installed to a single location, but it may be an acceptable solution for you.
  3. Do some initialization (e.g. setting your environment variable) on ‘first launch’ of your package/extension within VS. This of course, means that users will have to know this is a necessary post-installation step.

I realize that none of these solutions is ideal. Please know that better MSBuild support with VSIX is our top requested feature, so we’ve definitely received the feedback.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文