Skip to content

Commit 642eed5

Browse files
authored
Update native File.Exists (#9223)
* Enable test ProjectItemSpecTooLong * Get full path * Get the rootlength from tempProject * Update the test exception * Update the test description * Update test description * Update WindowsFileSystem.FileExists * revert test description * Adds all assembly redirects to the config file
1 parent 1205246 commit 642eed5

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

src/Build.UnitTests/BackEnd/MSBuild_Tests.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,13 @@ public void Dispose()
3737
/// throw a path too long exception
3838
/// </summary>
3939
[Fact]
40-
[ActiveIssue("https://github.com/dotnet/msbuild/issues/4247")]
4140
public void ProjectItemSpecTooLong()
4241
{
4342
string currentDirectory = Directory.GetCurrentDirectory();
4443
try
4544
{
4645
Directory.SetCurrentDirectory(Path.GetTempPath());
4746

48-
string tempPath = Path.GetTempPath();
49-
5047
string tempProject = ObjectModelHelpers.CreateTempFileOnDisk(@"
5148
<Project DefaultTargets=`TargetA; TargetB; TargetC` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
5249
@@ -68,16 +65,16 @@ public void ProjectItemSpecTooLong()
6865
projectFile1 += "..\\";
6966
}
7067

71-
int rootLength = Path.GetPathRoot(tempPath).Length;
72-
string tempPathNoRoot = tempPath.Substring(rootLength);
68+
int rootLength = Path.GetPathRoot(tempProject).Length;
69+
string tempPathNoRoot = tempProject.Substring(rootLength);
7370

74-
projectFile1 += Path.Combine(tempPathNoRoot, fileName);
71+
projectFile1 += tempPathNoRoot;
7572

7673
string parentProjectContents = @"
7774
<Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
7875
7976
<Target Name=`Build`>
80-
<MSBuild Projects=`" + projectFile1 + @"` />
77+
<MSBuild Projects=`" + projectFile1 + @"`/>
8178
</Target>
8279
</Project>";
8380
try

src/MSBuild.UnitTests/XMake_Tests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Reflection;
1212
using System.Runtime.InteropServices;
1313
using System.Threading;
14+
using System.Xml.Linq;
1415
using Microsoft.Build.CommandLine;
1516
using Microsoft.Build.Evaluation;
1617
using Microsoft.Build.Framework;
@@ -985,8 +986,8 @@ public void ConfigurationInvalid()
985986
var msbuildExeName = Path.GetFileName(RunnerUtilities.PathToCurrentlyRunningMsBuildExe);
986987
var newPathToMSBuildExe = Path.Combine(startDirectory, msbuildExeName);
987988
var pathToConfigFile = Path.Combine(startDirectory, msbuildExeName + ".config");
988-
989-
string configContent = @"<?xml version =""1.0""?>
989+
XElement configRuntimeElement = XDocument.Load(RunnerUtilities.PathToCurrentlyRunningMsBuildExe + ".config").Root.Element("runtime");
990+
string configContent = $@"<?xml version =""1.0""?>
990991
<configuration>
991992
<configSections>
992993
<section name=""msbuildToolsets"" type=""Microsoft.Build.Evaluation.ToolsetConfigurationSection, Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"" />
@@ -1006,6 +1007,7 @@ public void ConfigurationInvalid()
10061007
<foo/>
10071008
</msbuildToolsets>
10081009
<foo/>
1010+
{configRuntimeElement}
10091011
</configuration>";
10101012
File.WriteAllText(pathToConfigFile, configContent);
10111013

src/Shared/FileSystem/WindowsFileSystem.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ public override bool DirectoryExists(string path)
6060

6161
public override bool FileExists(string path)
6262
{
63-
return NativeMethodsShared.FileExistsWindows(path);
63+
#if NETFRAMEWORK
64+
return Microsoft.IO.File.Exists(path);
65+
#else
66+
return File.Exists(path);
67+
#endif
6468
}
6569

6670
public override bool FileOrDirectoryExists(string path)

src/Tasks.UnitTests/MSBuild_Tests.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,13 @@ public void Dispose()
3939
/// throw a path too long exception
4040
/// </summary>
4141
[Fact]
42-
[ActiveIssue("https://github.com/dotnet/msbuild/issues/4247")]
4342
public void ProjectItemSpecTooLong()
4443
{
4544
string currentDirectory = Directory.GetCurrentDirectory();
4645
try
4746
{
4847
Directory.SetCurrentDirectory(Path.GetTempPath());
4948

50-
string tempPath = Path.GetTempPath();
51-
5249
string tempProject = ObjectModelHelpers.CreateTempFileOnDisk(@"
5350
<Project DefaultTargets=`TargetA; TargetB; TargetC` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
5451
@@ -70,10 +67,10 @@ public void ProjectItemSpecTooLong()
7067
projectFile1 += "..\\";
7168
}
7269

73-
int rootLength = Path.GetPathRoot(tempPath).Length;
74-
string tempPathNoRoot = tempPath.Substring(rootLength);
70+
int rootLength = Path.GetPathRoot(tempProject).Length;
71+
string tempPathNoRoot = tempProject.Substring(rootLength);
7572

76-
projectFile1 += Path.Combine(tempPathNoRoot, fileName);
73+
projectFile1 += tempPathNoRoot;
7774
try
7875
{
7976
MSBuild msbuildTask = new MSBuild

0 commit comments

Comments
 (0)