How to connect to Shared Drive/Folder using a net command from MSBuild script?

Today, I gonna share the useful command that how we can connect to the shared drive/folder using a net command from MSBuild script.

  1. Install the MSBuildTasks package from NuGet package manager. My one is version 1.5.0.235.
  2. Import the package to your project file.
    <Import Project="packages\MSBuildTasks.15.0.235\tools\MSBuild.Community.Tasks.Targets"/>
  3. Create the new Target to connect to the shared drive/folder.
    <Target Name="ShareFolder">
    <Exec Command="net use <drive>\\<servername>\<sharefolder> /user:<username> <password> "
    </Target>

That’s it. I hope this will help. ๐Ÿ™‚
Photo: Internet

Leave a Reply

Your email address will not be published. Required fields are marked *