2

I need help getting the AppData Local directory for MSBuild.

File Explorer:

%LOCALAPPDATA%

C#:

System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData)

PowerShell:

$([System.Environment]::GetFolderPath("LocalApplicationData"))

I've tried the following four variations to get it for MSBuild:

<PropertyGroup>
    <AppDataLocalDir1>$([System.Environment]::GetFolderPath([System.Environment.SpecialFolder]::LocalApplicationData))</AppDataLocalDir1>
    <AppDataLocalDir2>$([System.Environment]::GetFolderPath([System.Environment.SpecialFolder.LocalApplicationData]))</AppDataLocalDir2>
    <AppDataLocalDir3>([System.Environment]::GetFolderPath("LocalApplicationData"))</AppDataLocalDir3>
    <AppDataLocalDir4>([System.Environment]::GetFolderPath('LocalApplicationData'))</AppDataLocalDir4>
</PropertyGroup>

I feel that my syntax must be close, as this works to get the current date:

<PropertyGroup>
    <Today>$([System.DateTime]::Now.ToString('yyyy.MM.dd'))</Today>
</PropertyGroup>

I have found sources that state that MSBuild can call [System.Environment]::GetFolderPath, but I cannot find any that show the syntax for passing in an argument.

Thanks a lot in advance.

1
  • I found the answer, which is to use $(LocalAppData), which is based on this answer here: stackoverflow.com/a/23120542/10429. I'm leaving the question up, because the question about the calling syntax for .NET classes from MSBuild is still relevant. Commented Jun 20, 2022 at 16:14

1 Answer 1

3

From "Property Functions: GetFolderPath" the syntax for the enum for GetFolderPath is:

<PropertyGroup>
    <AppDataLocalDir>$([System.Environment]::GetFolderPath(SpecialFolder.LocalApplicationData))</AppDataLocalDir>
</PropertyGroup>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Jonathan -- this corrects my syntax for accessing the enum. I was also able to make use of $(LocalAppData), which seems to be practically undocumented.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.