views:

48

answers:

1

Hi all:

Currently I'm trying to copy a file to a location inside a user's profile, but hit a problem with declaring dynamic profile name, e.g.:

<Target Name="CopyScript">
    <MsBuild Projects="JsProject.csproj" />
    <Copy SourceFiles="$(ProjectDir)\myScript.js" DestinationFolder="$(systemdrive)\Documents and Settings\$(userProfileName)" />
</Target>

What is the syntax for declaring a dynamic user profile name? Do I have to get the profile name from somewhere, or is there another MsBuild task which will find it for me?

Thanks.

+1  A: 

You should be able to get this with the HOMEDRIVE and HOMEPATH env variables. For example:

<Project ToolsVersion="3.5" DefaultTargets="Demo" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;

    <PropertyGroup>
  <UserDir>$(HOMEDRIVE)$(HOMEPATH)</UserDir>
 </PropertyGroup>

  <Target Name="Demo">
 <Message Text="UserDir : $(UserDir)" Importance="High" />
  </Target>

</Project>

When you execute the Demo target you should get the path to the current users home directory.

Sayed Ibrahim Hashimi
@ Sayed: I used your example, and it returned "C:\Documents and Settings\Administrator". If I only want it to return "Administrator", do I just use something like $(username)?
BeraCim
In that case you would use the env variable USERNAME so $(USERNAME)
Sayed Ibrahim Hashimi