Created
September 21, 2017 09:12
-
-
Save lennybacon/b4ace8fc116edb63d5c18b2a80cefd0e to your computer and use it in GitHub Desktop.
CredentialManager.msbuild
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<Project ToolsVersion="15.0" DefaultTargets="GetCredentials" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<UsingTask | |
TaskName="CredentialManager" | |
TaskFactory="CodeTaskFactory" | |
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" > | |
<ParameterGroup> | |
<Target ParameterType="System.String" Required="true" /> | |
<UserName ParameterType="System.String" Output="true" /> | |
<Password ParameterType="System.String" Output="true" /> | |
</ParameterGroup> | |
<Task> | |
<!-- CredentialManagement: nuget install CredentialManagement --> | |
<Reference Include=".\CredentialManagement.1.0.2\lib\net35\CredentialManagement.dll"/> | |
<Using Namespace="System"/> | |
<Using Namespace="CredentialManagement"/> | |
<Code Type="Fragment" Language="cs"> | |
<![CDATA[ | |
var cm = new Credential {Target = Target}; | |
if (!cm.Load()) | |
{ | |
Log.LogError("Add credentials for '" + Target + "' to the windows credential manager by running the following command line: cmdkey.exe /generic:Build /user:{UserName}} /pass:{Password}"); | |
return false; | |
} | |
UserName = cm.Username; | |
Password = cm.Password; | |
return true; | |
]]> | |
</Code> | |
</Task> | |
</UsingTask> | |
<Target Name="GetCredentials"> | |
<CredentialManager Target="Build2"> | |
<Output TaskParameter="UserName" PropertyName="UserName"/> | |
<Output TaskParameter="Password" PropertyName="Password"/> | |
</CredentialManager> | |
<Message Text="Username '$(UserName)' with password '$(Password)'" /> | |
</Target> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment