VS 2010 多项目模板:项目间参考 [英] VS 2010 Multi-Project Template: Inter-Project References

查看:25
本文介绍了VS 2010 多项目模板:项目间参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个多项目模板.我正在使用此处记录的方法:如何:创建多项目模板.该模板将有一个主网站模板(仿照 MVC 3 模板)和一些额外的调用库模板,以保持功能分离.

I am currently developing a multi-project template. I am using the approach documented here: How to: Create Multi-Project Templates. This template will have a main web site template (modeled after the MVC 3 temaplte) and a few additional calls library templates to keep functionality separate.

示例:WebsiteProject1 位于模板项目的一个文件夹中,并且在该文件夹下包含其所有文件和 .vstemplate.ClassLibrary1 位于模板项目的另一个文件夹下,并且也有自己的 .vstemplate 文件.

Example: WebsiteProject1 lives in a folder in the template project and has all of its files and .vstemplate under that folder. ClassLibrary1 lives under another folder in the template project and also has its own .vstemplate file.

我的问题是,如何在网站项目 1 中为 ClassLibrary1 设置引用,以便在从模板创建项目时,引用存在并解析?这甚至可能吗?

My question is, how do I set up references in the WebsiteProject1 for ClassLibrary1 so that when the project is created from the template, the references are present and resolve? Is this even possible?

推荐答案

我今天正在做一个类似的设置,我发现这确实是可能的,但它需要在导出模板后手动调整您的 WebsiteProject 的 csproj 文件.还有一些错误,即 ProjectReference 标记下的 Name 标记中没有标记替换.

I was working on a similar setup today and I found that it is indeed possible but it requires a manual adaption of the csproj file of your WebsiteProject after exporting the template. Also there's some kind of bug where there's no token replacement in the Name tag under the ProjectReference tag.

基本上您希望 csproj 文件包含以下内容:

Basicly you want the csproj file to contain the following:

<ItemGroup>
    <ProjectReference Include="..\$SolutionName$.Library\$SolutionName$.Library.csproj">
        <Project>{8a8efea7-e80c-4de2-8c35-ced49a814675}</Project>
        <Name>ClassLibrary</Name>
    </ProjectReference>
</ItemGroup>

请注意,我没有替换 <Name>标记值,因为令牌替换不起作用.幸运的是,这似乎并没有妨碍参考文献的工作.

Note that I did not replace the <Name> tag value since the token replacements don't work. Luckily this doesn't seem to hinder the working of the reference.

编辑:使用 $safeprojectname$ 将引用项目本身.如果你的类库有一个硬编码的名字,这不是一个真正的问题,但在我的情况下,我想要一个像NewProject.Library"这样的名字,我通过在我的多项目 vstemplate 文件中添加一个像这样的 CustomParameter $SolutionName$ 来解决这个问题:

EDIT: Using the $safeprojectname$ will refer to the project itself. If your class library has a hardcoded name this isn't really a problem but in my case I wanted a name like "NewProject.Library" I solved this by adding a CustomParameter $SolutionName$ like this in my Multi Project vstemplate file:

<CustomParameters>
  <CustomParameter Name="$SolutionName$" Value="$safeprojectname$"/>
</CustomParameters>

这篇关于VS 2010 多项目模板:项目间参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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