C# 纽吉公司;通过API生成MSBuild-未执行目标文件
现在,当通过Windows服务执行时,我无法使其工作。 它总是跳过自定义目标C# 纽吉公司;通过API生成MSBuild-未执行目标文件,c#,visual-studio,msbuild,nuget,targets,C#,Visual Studio,Msbuild,Nuget,Targets,现在,当通过Windows服务执行时,我无法使其工作。 它总是跳过自定义目标 我必须通过进程将重新生成步骤集成到我的构建任务中。从specflow.exe开始。您是否也以编程方式执行nuget还原 因为它看起来像是在评估为false: public static bool BuildWithMSBuild(string solution) { string command = solution; ProcessStartInfo p
我必须通过进程将重新生成步骤集成到我的构建任务中。从specflow.exe开始。您是否也以编程方式执行nuget还原 因为它看起来像是在评估为false:
public static bool BuildWithMSBuild(string solution)
{
string command = solution;
ProcessStartInfo psi = new ProcessStartInfo(PathToMSBuild());
psi.Arguments = command;
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
Process p = new Process();
p.StartInfo = psi;
p.Start();
var v = p.StandardOutput.ReadToEnd();
Console.Write(v);
p.WaitForExit(60000);
File.WriteAllText("buildresult.txt",v);
if (v.Contains("Build succeeded"))
{
return true;
}
return false;
}
属性仅在从IDE生成时定义。请尝试在生成工具中定义它。但是,此目标未使用$(SolutionDir)?我将它定义为什么-它必须是到项目目录的动态var映射。正在报告的消息听起来不像是错误消息-它说它正在将语句评估为false-这意味着!Exists==false与说“是目标文件确实存在”相同。请检查在还原nuget包后,
MainFramework.targets
是否存在于生成服务器上的packages文件夹中。您是否已尝试在生成服务器上使用MSBuild cli生成自定义生成工具?我可以确认生成服务器上存在目标文件。似乎是环境因素造成的。我能想到的唯一区别是,在构建服务器上,通过VisualStudio运行该工具和通过cmd提示符在本地运行该工具时,它是作为Windows服务的系统帐户运行的。奇怪的是,日志中的消息表明它正在查找目标文件——因为它在说!Exists==false。只有当它存在==false时才是负数-对吗?此外-没有出现错误文本,表明它没有未能找到目标file@Baaleos是的,你是对的。如果服务器上不存在MainFramework.targets
,导入将抛出一个错误,即找不到MainFramework.targets。您是否尝试在生成服务器上直接使用MSBuild cli而不使用TFS/VSTS生成它。。。如果它与MSBuild配合良好,则与TFS/VSTS配合良好…,顺便说一句,您在生成服务器上使用的MSBuild的版本是什么。我执行nuget还原和更新。奇怪的是,当我在VisualStudio中逐步使用该工具时,它可以在本地工作。但是,当我在构建服务器上运行它时,它的行为会有所不同。它作为windows服务在系统帐户下运行。
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
<Error Condition="!Exists('..\packages\MainFramework.0.15.0\build\MainFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MainFramework.0.15.0\build\MainFramework.targets'))" />
</Target>
<PropertyGroup>
<PreBuildEvent>
</PreBuildEvent>
</PropertyGroup>
<Import Project="..\packages\MainFramework.0.15.0\build\MainFramework.targets" Condition="Exists('..\packages\MainFramework.0.15.0\build\MainFramework.targets')" />
ProjectCollection pc = new ProjectCollection();
Dictionary<string, string> globalProperty = new Dictionary<string, string>();
globalProperty.Add("nodeReuse", "false");
BuildParameters bp = new BuildParameters(pc);
bp.Loggers = new List<Microsoft.Build.Framework.ILogger>()
{
new FileLogger() {Parameters = @"logfile=buildresult.txt", Verbosity = LoggerVerbosity.Diagnostic}
};
BuildRequestData buildRequest = new BuildRequestData(projectFilePath, globalProperty, "12.0",
new string[] { "Clean", "Build" }, null);
BuildResult buildResult = BuildManager.DefaultBuildManager.Build(bp, buildRequest);
BuildManager.DefaultBuildManager.Dispose();
pc = null;
bp = null;
buildRequest = null;
public static bool BuildWithMSBuild(string solution)
{
string command = solution;
ProcessStartInfo psi = new ProcessStartInfo(PathToMSBuild());
psi.Arguments = command;
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
Process p = new Process();
p.StartInfo = psi;
p.Start();
var v = p.StandardOutput.ReadToEnd();
Console.Write(v);
p.WaitForExit(60000);
File.WriteAllText("buildresult.txt",v);
if (v.Contains("Build succeeded"))
{
return true;
}
return false;
}
Exists('$(SolutionDir).nuget\NuGet.targets')