我如何编程方式从C#code建立我的解决方案文件? [英] How can I programmatically build my solution files from C# code?

查看:85
本文介绍了我如何编程方式从C#code建立我的解决方案文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有包含许多个项目,其中之一是安装项目的大型解决方案。有也存储在单独的分支许多当前版本。我有一个构建工具,用于.NET 2的工作,但没有工作,因为我们升级到.NET 4中。

I have a large solution containing many projects with one of them being a Setup project. There are also many current versions stored in separate branches. I have a build tool that used to work in .NET 2, but hasn't worked since we upgraded to .NET 4.

在内部,构建工具的新的.NET 4的版本使用 Microsoft.TeamFoundation.Client.RegisteredTfsConnections.GetProjectCollections() versionControlServer.GetAllTeamProjects (假)从我的TFS源代码控制服务器获取 TeamProject s的集合。

Internally, the new .NET 4 version of the build tool uses Microsoft.TeamFoundation.Client.RegisteredTfsConnections.GetProjectCollections() and versionControlServer.GetAllTeamProjects(false) to get a collection of TeamProjects from my TFS source control server.

然后我在UI直观地显示他们当用户点击一个特定的解决方案版本,应用程序调用下面以获得最新的该解决方案版本:

I then display them visually in the UI and when a user clicks on a particular solution version, the application calls the following to get the latest for that solution version:

workspace.Get(new string[] { serverPath }, VersionSpec.Latest, RecursionType.Full, 
   GetOptions.GetAll);

用于构建解决方案文件的应用程序,这将包括安装项目。在此阶段,安装项目将创建一个应用程序可以与安装的MSI。这是我有问题,这最后一步。

The application used to build the solution files and this would include the Setup project. At this stage, the setup project would create an MSI that the application could be installed with. It is this last step that I am having problems with.

我需要能够以编程方式生成用户使用C#code选择的解决方案。工作.NET 2 code这个如下:

I need to be able to programmatically build the solution that the user selected using C# code. The working .NET 2 code for this was as follows:

Process process = new Process();
ProcessStartInfo processStartInfo = process.StartInfo;
processStartInfo.FileName = processName;
processStartInfo.Arguments = string.Format(" \"{0}\" /BUILD \"Release|Any CPU\"", 
   solutionPath);
processStartInfo.WorkingDirectory = processDirectory;
process.Start();

有当这是运行没有错误,但它不再启动Visual Studio和构建code。显然,这是一个贫穷的方式来开始做它,但使用TFS类我无法找到正确的方式。

There is no error when this is run, but it no longer launches Visual Studio and builds the code. Clearly, this was a poor way to do it initially, but I can't find the 'correct' way using the TFS classes.

我也试过运行MSBuild.exe直接(类似于上面的例子),这确实构建解决方案,但由于某种原因不能建立一个生产的MSI安装项目。请注意,我不使用任何手动创建的构建文件。

I also tried running MSBuild.exe directly (similar to the above example), and this does build the solution, but for some reason does not build the Setup project that produces the MSI. Note that I do NOT use any manually created build files.

不幸的是,对于Microsoft.TeamFoundation空间有用的文档是很难找到的!我希望有人在这里取得了使用这些类和可以直接给我解决了这个问题。

Unfortunately, useful documentation for the Microsoft.TeamFoundation namespace is hard to find! I'm hoping that someone here has made use of these classes and can direct me to a solution to this problem.

如果可能的话,我需要使用.NET类(如没有的Process.Start),因为我真的很需要知道什么时候构建完成为好。不过,我可以成立一个 FileSystemWatcher的对象这一点,如果这是太奢侈了。

If at all possible, I need to use .NET classes (eg. not Process.Start) as I really need to know when the build has finished as well. I can however set up a FileSystemWatcher object for this if this is asking too much.

推荐答案

原来,问题是不幸的是完全无关的。在.NET 2 code,这是被更新了好大劲才codeD程序文件到devenv.exe的文件路径 - 但是新的计算机是64位和Visual Studio 2010安装到程序文件(x86) '!

It turns out that the problem was unfortunately completely unrelated. The .NET 2 code that was to be updated had hard coded 'Program Files' into the devenv.exe file path - however the new computers are 64bit and Visual Studio 2010 is installed into 'Program Files (x86)'!

因此​​,这意味着,上述code样本中的工作,可以让我建立从C#的解决方案。这并不是说我会有preferred做面向对象的方式,但您的所有意见后,我只是很高兴已完成了所有的工作。

So this means that the above code sample DOES work and WILL allow me to build the solutions from C#. It's not the object oriented way that I would have preferred to do it, but after all your comments, I'm just glad to have got it working at all.

感谢您的时间每个人。

这篇关于我如何编程方式从C#code建立我的解决方案文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆