Skip to content

Commit

Permalink
Merge pull request #1446 from rainersigwald/ignore-implicit-on-remove
Browse files Browse the repository at this point in the history
Ignore implicit on remove
  • Loading branch information
AndyGerlicher authored Dec 6, 2016
2 parents 19df8c8 + 6c723e9 commit 28031e6
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/BuildValues.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
prerelease version number and without the leading zeroes foo-20 is
smaller than foo-4.
-->
<RevisionNumber>00078</RevisionNumber>
<RevisionNumber>00079</RevisionNumber>
</PropertyGroup>
</Project>
5 changes: 5 additions & 0 deletions src/XMakeBuildEngine/Construction/ProjectElementContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,11 @@ private string GetElementIndentation(XmlElementWithLocation xmlElement)

internal void RemoveFromXml(ProjectElement child)
{
if (child.IsImplicit)
{
return;
}

if (child.ExpressedAsAttribute)
{
XmlElement.RemoveAttribute(child.XmlElement.Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,60 @@ public void ProjectWithSdkImportsIsCloneable()
}
}
}

[Fact]
public void ProjectWithSdkImportsIsRemoveable()
{
var testSdkRoot = Path.Combine(Path.GetTempPath(), "MSBuildUnitTest");
var testSdkDirectory = Path.Combine(testSdkRoot, "MSBuildUnitTestSdk", "Sdk");

try
{
Directory.CreateDirectory(testSdkDirectory);

string sdkPropsPath = Path.Combine(testSdkDirectory, "Sdk.props");
string sdkTargetsPath = Path.Combine(testSdkDirectory, "Sdk.targets");

File.WriteAllText(sdkPropsPath, "<Project />");
File.WriteAllText(sdkTargetsPath, "<Project />");

using (new Helpers.TemporaryEnvironment("MSBuildSDKsPath", testSdkRoot))
{
// Based on the new-console-project CLI template (but not matching exactly
// should not be a deal-breaker).
string content = @"<Project Sdk=""Microsoft.NET.Sdk"" ToolsVersion=""15.0"">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include=""**\*.cs"" />
<EmbeddedResource Include=""**\*.resx"" />
</ItemGroup>
<ItemGroup>
<PackageReference Include=""Microsoft.NETCore.App"" Version=""1.0.1"" />
</ItemGroup>
</Project>";

ProjectRootElement project = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
ProjectRootElement clone = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));

clone.DeepCopyFrom(project);

clone.RemoveAllChildren();
}
}
finally
{
if (Directory.Exists(testSdkRoot))
{
FileUtilities.DeleteWithoutTrailingBackslash(testSdkDirectory, true);
}
}
}

}
}

0 comments on commit 28031e6

Please sign in to comment.