powershell - 从 Powershell 打包 Visual Studio 项目

标签 powershell visual-studio-2012 build-automation packaging

哦,伟大的 powershell 众神,请向这个异教徒展示光明!

我的任务是创建一个一键式将我们的解决方案发布到云端的 powershell 脚本。然而,我一生中从未使用过 PS。因此,我一直在进行大量谷歌搜索并找到了很多信息,但是在我想开始的地方我很难找到我可以全神贯注的东西。

我一直在运行前/后构建脚本、VS 管理控制台、nuget 包管理或任何其他数量看似无关的信息。这些不是我要找的。

通过此处的示例或链接到一个很好的教程来帮助我入门。我的第一步是让 VS 打包解决方案以供发布。通过PS做以下 Action 。

Image for clarity, just in case...

我认为这是最容易找到关于...的信息的方法。我已经看到一些关于 MSBuild 的信息,我现在正在研究这些信息,希望能在这里得到答案。

编辑:我的工作 PS 脚本

$msbuild = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe" # Reference to the MSBuild.exe for .NET 4.0
$path = "C:\myProj\"                                  # Path to the project you want to publish to Azure 

# Clean the solution
& $msbuild ($path + "Source\pathToYour\AzureMyProj.ccproj") /target:clean /p:Configuration=Release

# Package the solution
& $msbuild ($path + "Source\pathToYour\AzureMyProj.ccproj") /target:publish /p:Configuration=Release

最佳答案

您可以为此目的使用 MSBuild。这就是我为我的项目做的:

所以在 powershell 中,你可以这样调用它:

.\MSBuild MyProject.proj /target:package /p:Configuration=Release

编辑 25/06:为詹姆斯工作 /target:publish

注意:您可能需要将 MSBuild 的位置指定为变量,这可以在 C:\Windows\Microsoft.Net\Framework\ 下找到版本号 \

在那种情况下它会变成:

$msbuild = "C:\Windows\Microsoft.NET\Framework64\v2.0.50727\msbuild.exe"
& $msbuild MyProject.proj /target:package /p:Configuration=Release

注意 &而不是 .\这告诉 powershell 执行变量(在本例中是一个 exe)。

另外,除了你不知道如何去做的问题。我使用一种称为 PSake 的构建语言,它是一种基于 PowerShell 的构建语言,可能对您有用。它非常有用:https://github.com/psake/psake

希望这对您有所帮助。

关于powershell - 从 Powershell 打包 Visual Studio 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17178661/

相关文章:

xml - TFS 2010/代码度量集成,自动构建失败,代码度量不运行

git - -split ' ' 在 Powershell 中本地工作在 Azure 管道 Powershell 任务中不起作用

c++ - Windows 上的 DLL 项目 : Unresolved External Symbol

visual-studio-2012 - 无法加载 "Aurigma Graphicsmill",加载格式不正确的程序

visual-studio-2012 - 如何在不安装Visual Studio 2012的情况下使用MsBuild在生成服务器上生成Visual Studio 2012发布配置文件

jenkins - Jenkins 中的构建超时插件 : how long is 'too long' ?

sql-server - 如何显示从 SQL Server 2008 R2 作业调用的 PowerShell 步骤中的错误?

powershell - PowerShell 中的整数除法

sql-server - 调用-Sqlcmd : A network-related or instance-specific error occurred while establishing a connection to SQL Server

.net - Visual Studio 2012 4 个项目中的 1 个未加载