在c#解决方案中,我添加了一个现有的项目。 在此之后,Visual Studio在其他.csproj文件中添加了以下条目:

<ItemGroup>
    <Service Include="{B4F97281-0DBD-4835-9ED8-7DFB966E87FF}" />
</ItemGroup>

这是干什么用的? 我可以删掉吗?


当前回答

我有一个类似的案例,其中添加了这个:

<ItemGroup>
  <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>

如果你创建了一个NUnit测试项目,但是忘记把它标记为测试项目,这个包含结果是由VS2013故意生成的,正如微软的回答所描述的那样:

This behavior is intentional. To support third-party test frameworks, like NUnit and XUnit, Visual Studio 2012 loaded Test Explorer on solution open, regardless of whether it contained test projects. This added seconds of delay to startup and solution open scenarios for all users, majority of whom don't use tests. In Visual Studio 2013, we changed it so that Test Explorer package is loaded only when the solution contains one or more test projects. Test projects are identified in two different ways. Projects created from one of the built-in unit test project templates are identified using project type GUIDs. Other types of projects, such as Class Library project with XUnit or NUnit tests, are identified by Test Explorer during first test discovery and “tagged” with the <Service/> item.

其他回答

众所周知的/恒定的guid的好处是它们非常独特,因此很容易在谷歌中搜索。我照做了,发现: 这个和这个,还有其他有趣的热门话题。 看起来这实际上是SDK附带的T4 DSL工具中的一个已知错误。幸运的是,通过更改一些注册表项就可以很容易地解决这个问题。

我有一个类似的案例,其中添加了这个:

<ItemGroup>
  <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>

如果你创建了一个NUnit测试项目,但是忘记把它标记为测试项目,这个包含结果是由VS2013故意生成的,正如微软的回答所描述的那样:

This behavior is intentional. To support third-party test frameworks, like NUnit and XUnit, Visual Studio 2012 loaded Test Explorer on solution open, regardless of whether it contained test projects. This added seconds of delay to startup and solution open scenarios for all users, majority of whom don't use tests. In Visual Studio 2013, we changed it so that Test Explorer package is loaded only when the solution contains one or more test projects. Test projects are identified in two different ways. Projects created from one of the built-in unit test project templates are identified using project type GUIDs. Other types of projects, such as Class Library project with XUnit or NUnit tests, are identified by Test Explorer during first test discovery and “tagged” with the <Service/> item.

就我个人而言,我不喜欢把这项服务添加到我的项目文件中,我认为它更像是一种变通办法,而不是一个正确的解决方案。所以把你的测试项目标记为测试项目对我来说似乎更正确,这可以通过添加到第一个PropertyGroup来实现:

<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TestProjectType>UnitTest</TestProjectType>

{3AC096D0-A1C2-E12C-1390-A8335801FDAB}表示测试项目和{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - c#。对于其他项目类型的向导,请点击这里