forked from Particular/docs.particular.net
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectFrameworks.cs
More file actions
48 lines (43 loc) · 1.72 KB
/
ProjectFrameworks.cs
File metadata and controls
48 lines (43 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.Linq;
using System.Xml.Linq;
using System.Xml.XPath;
using NUnit.Framework;
namespace IntegrityTests
{
public class ProjectFrameworks
{
[Test]
public void DoNotUseTargetFrameworksPlural()
{
new TestRunner("*.csproj", "Project files should not be multi-targeted with <TargetFrameworks> element")
.IgnoreSnippets()
.Run(projectFilePath =>
{
var xdoc = XDocument.Load(projectFilePath);
if (xdoc.Root.Attribute("xmlns") != null)
{
return true;
}
var firstTargetFrameworksElement = xdoc.XPathSelectElement("/Project/PropertyGroup/TargetFrameworks");
return firstTargetFrameworksElement == null;
});
}
[Test]
public void EnsureSingleTargetFramework()
{
new TestRunner("*.csproj", "Project files should only contain a single <TargetFramework> element")
.Run(projectFilePath =>
{
var xdoc = XDocument.Load(projectFilePath);
if (xdoc.Root.Attribute("xmlns") != null)
{
return true;
}
var targetFrameworkElements = xdoc.XPathSelectElements("/Project/PropertyGroup/TargetFramework");
// Project may have zero of these if it has TargetFrameworks, but then it fails DoNotUseTargetFrameworksPlural
// Projects with no target framework will not build at all
return targetFrameworkElements.Count() <= 1;
});
}
}
}