Fix issue 11820 Add DirectoryExists() and FileExists() function#11919
Conversation
SimaTian
left a comment
There was a problem hiding this comment.
Nice one. Thank you for your help.
|
This looks like a good implementation, but my first instinct is to add @KirillOsenkov, you asked for |
|
Makes sense, I also favor "both/and". @huulinh99, would you be interested in enabling msbuild/src/Build/Resources/Constants.cs Lines 322 to 326 in 6de6474 |
|
Hi @rainersigwald , thank you so much for your comment, I will enable Directory.Exists in this PR |
|
Quick question, will the syntax such as |
That is entirely separate (😔) . . . but a reasonable request. |
|
wait, there are three syntaxes? I guess ideally I was asking for the syntax without the :: 😅 |
|
Hi @rainersigwald @KirillOsenkov Could you confirm again that you are expecting both syntax Condition="$([System.IO.Directory]::Exists('foo'))" and Condition="DirectoryExists('foo')" to work well? |
|
Rainer says it's a separate mechanism, perhaps we can merge this PR and do that syntax separately, or do it as part of this PR, or not do it at all. My apologies that the scope keeps increasing :) Let's see what Rainer thinks. When I originally filed this issue, I wanted |
rainersigwald
left a comment
There was a problem hiding this comment.
Yeah we don't have to add any more functionality to this PR, let's merge with this (after adding the Directory.Exists test).
I would be happy for a follow-up PR to add the condition "functions" in FunctionCallExpressionNode.cs though!
|
Thank you for your comment @rainersigwald @KirillOsenkov , I will do base on your suggestion |
|
@dotnet-policy-service agree |
|
Thank you so much @huulinhnguyen-dev! |

Fixes #
Fix the issue 11820, add two function DirectoryExists() and FileExists() #11820
Context
Currently, doesn't have any goodway to check the File or the Directory is exist or not, and the [System.IO.Directory]::Exists() is not allowed.
Changes Made
Add two function DirectoryExists() and FileExists() in the msbuild, now we can use [MSBuild]::FileExist() or [MSBuild]::DirectoryExists() in the project files
Testing
I have performed testing for various exception to validate the changes. Tested two case FileExists and DirectoryExist
Notes