信息: C#、Visual Studio 2010 RC

如何通过代码将 WCF Web 服务项目项添加到我的项目中?

我可以添加一个代码类文件没有问题:

string csItemTemplatePath = soln.GetProjectItemTemplate("CodeFile", "CSharp");

try
{
    projectItems.AddFromTemplate(csItemTemplatePath, fileName);
}
catch (Exception ex)
{
    // This is just testing, don't shoot me
    MessageBox.Show(ex.Message);
} 

但如果我尝试使用:

string itemTemplatePath = soln.GetProjectItemTemplate("WebWcfService", "CSharp");

我收到一个异常,无法找到它

该系统找不到指定的文件。(HRESULT 的异常:0x80070002)

我从以下位置获得了 WebWcfService 名称:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Web\1033

我认为这与解决方案如何查找其项目项有关,但我不知道如何做到这一点。

有帮助吗?

解决方案

这是为我回答的 http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/7f031537-f8c0-4281-bda1-c56cf86b2109

嗨,菲尔

因为WebWwcfService是一个Web项目,它是CSHARP项目的子类型。因此,我们需要以这种方式找到WebWcfService。

string path = soln.GetProjectItemTemplate("WebWcfService.zip", CSharp/Web");

如果您有任何不清楚的东西,请随时告诉我。

谢谢

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top