【发布时间】:2013-12-17 20:22:03
【问题描述】:
我正在编写一个构建应用程序,该应用程序可以从 TFS 获取最新代码,然后将它们构建到 DLL 中。此应用程序托管为 ASP.NET Web 应用程序,应用程序池使用我的域帐户运行。
我们的代码使用NuGet 来管理依赖关系。我们的 Intranet 中有一个本地存储库,一些依赖项ONLY 在这个本地存储库中。
如果我在 CMD 中运行以下命令,
D:\MyApplication\nuget.exe restore
结果是:
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.
所有依赖都可以正确下载。但在我的 C# 代码中
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();
除非我取消注释Password、UserName、Domain,否则明确设置用户信息,我会收到以下错误:
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'.
我不知道为什么会这样?这个应用程序是我的账号运行的,我启动的Process也可能是我的账号运行的,这个命令在CMD下是可以运行的,为什么在我的C#代码中不行呢?
你会帮我吗?提前谢谢你。
PS:nuget配置如下:
%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>
--
更新:
我编写了一个控制台应用程序,将其重命名为 nuget.exe,并覆盖了真实的。
private static void Main(string[] args)
{
File.WriteAllText("D:\\temp\\user.txt", System.Security.Principal.WindowsIdentity.GetCurrent().Name);
}
它显示,nuget.exe 是使用我的域帐户运行的。
【问题讨论】:
-
@BlackICE 谢谢,我尝试将 UseShellExecute 设置为 true,但不起作用。