VSIX Flavored 项目自定义 .target 文件导入问题
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
[包括我之前通过电子邮件对同一问题的回复。]
Visual Studio 2010 不支持通过 VSIX 分发的 MSBuild 目标/任务。建议您使用 MSI(或类似的部署技术)并将目标文件拖放到您在 %ProgramFiles%\MSBuild 下选择的目录。然后,您可以通过 $(MSBuildExtensionsPath) 在项目模板中引用它们。
VSIX 安装本质上只是 VSIX 的“解压缩”。就是这样。无法注册或执行任何自定义操作。正如您所提到的,在构建时,会运行一个名为 CreatePkgDef.exe 的工具(它会加载程序集并调用 RegistrationAttribute)来创建 VSIX 中包含的 pkgdef 文件。
我认为您需要执行以下操作之一:
我意识到这些解决方案都不是理想的。请注意,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:
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.