I'm writing a building application, this application can get the latest code from TFS, and then build them into DLLs. This application is hosted as ASP.NET web application, the application pool is run with my domain account.
Our code use NuGet to manage dependencies. And we have a local repository in our intranet, some dependencies ONLY in this local repository.
If I ran below command in the CMD,
D:\MyApplication\nuget.exe restore
Result is:
Installing 'My_Dependency_Only_In_Local_1 1.0.0'.
Installing 'My_Dependency_Only_In_Local_2 2.0.0'.
Successfully installed 'My_Dependency_Only_In_Local_1 1.0.0'.
Successfully installed 'My_Dependency_Only_In_Local_2 2.0.0'.
All packages listed in packages.config are already installed.
All the dependencies can be downloaded correctly. But in my C# code
var processInfo = new ProcessStartInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "nuget.exe"), "restore " + localProjectPath)
{
WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory,
UseShellExecute = false,
RedirectStandardError = true,
CreateNoWindow = true,
//Password = mypassword,
//UserName = myusername,
//Domain = mydomainname
};
var process = Process.Start(processInfo);
process.WaitForExit();
string errorText = process.StandardError.ReadToEnd();
unless I uncomment the Password
, UserName
, Domain
, set the user info explicitly, I would got the below error:
Unable to find version '1.0.0' of package 'My_Dependency_Only_In_Local_1'.
Unable to find version '2.0.0' of package 'My_Dependency_Only_In_Local_2'.
I have no idea why this happened? This application is run by my account, and the Process
I started might also run by my account, this command is works when running in CMD, but why not in my C# code?
Would you help me? Thank you in advanced.
PS: the nuget configuration is like below:
%APPDATA%\NuGet\NuGet.Config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<packageSources>
<add key="intranet repository" value="http://our/local/nuget/repository" />
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</packageSources>
<disabledPackageSources>
<add key="local cache" value="true" />
</disabledPackageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>
--
UPDATE:
I wrote a console application, rename it to nuget.exe, and overwrites the real one.
private static void Main(string[] args)
{
File.WriteAllText("D:\\temp\\user.txt", System.Security.Principal.WindowsIdentity.GetCurrent().Name);
}
It shows, nuget.exe is run with my domain account.