如何创建包含链接文件的 Visual Studio 项目模板?
在 Visual Studio 2010 中,我想创建一个项目模板,其中包含系统上应存在的两个文件的链接。其中之一是常见的 AssemblyInfo.cs 文件。另一个是强名称密钥文件(*.snk)。
我需要这些引用是相对的,因为每个开发人员的工作区的设置都不同。项目模板是否有可能以某种方式找出这些文件驻留在每个开发人员环境中的位置?
从阅读有关模板的内容来看,听起来它们非常静态,所以我想知道是否可以采取一些技巧来完成这样的事情。如果不出意外,我可以添加虚假引用,这将导致编译错误并迫使开发人员挂钩这些文件。但如果我能为他们做到这一点,那就更好了。
In Visual Studio 2010, I want to create a project template that includes links to two files that should exist on the system. One of them is a common AssemblyInfo.cs file. Another is the strong name key file (*.snk).
I need these references to be relative, because each developer's workspace will be set up differently. Is it possible for the project template to somehow figure out where these files reside in each developer's environment?
From reading about templates, it sound like they're pretty static so I wonder if tricks can be done to do something like this. If nothing else, I can add bogus references that will cause compilation errors and force the developer to hook these files in. But if I can do it for them, that would be better.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该在 vstemplate 中将 CreateInPlace 属性设置为
true
。 文档说如果您希望相对路径起作用,则需要在创建项目的位置进行参数替换,而不是在临时位置。
You should set the CreateInPlace property to
true
in the vstemplate. The documentation saysIf you want relative paths to work, you need the parameter replacement to occur in the place where you're creating the project, not in a temporary location.
Microsoft 已确认这是可扩展性模型和项目模板的错误。我设法通过使用 IWizard 解决了这个问题。我在 IWizard 实现的 RunFinished 方法中添加了以下代码:
此代码将 TheFileIWantToLink.cs 文件的副本链接到我的共享 Silverlight 项目 (slSharedProject)。
Microsoft have confirmed that this is a bug with the extensibility model and project templates. I managed to get round this by using IWizard. I added the following code in the RunFinished method of my IWizard implementation:
This code links in a copy of TheFileIWantToLink.cs file to my shared Silverlight project (slSharedProject).
您可以尝试将向导集成到项目模板中,并将路径设置为链接文件。如果我没记错的话,您不必创建用户界面;您只需在replacementsDictionary 中指定正确的替换,VS 将替换模板文件中的值。请参阅此或此了解更多信息。
You could try to integrate a Wizard into your Project Template and set the Paths to the linked files. If i remember right you don't have to create an User Inteface; you only have to specify the correct replacements in the replacementsDictionary and VS will replace the values in your Template File. See this or this for further information.