visual-studio 如何在 Visual Studio 2008 中自动发布网站?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2262478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 11:32:48  来源:igfitidea点击:

How to automatically publish a website on build in Visual Studio 2008?

c#asp.netasp.net-mvcvisual-studiovisual-studio-2008

提问by Rohit

I want to be able to automatically publish to a local folder each time a web asp.net mvc 2 project is built.

我希望能够在每次构建 web asp.net mvc 2 项目时自动发布到本地文件夹。

I use Visual Studio 2008.

我使用 Visual Studio 2008。

采纳答案by Peter Oehlert

The easiest way to automate the functionality included in Visual Studio's "publish" action available from the Build menu is to use the web deployment project. There's one for VS2005 as well. Basically it's an extra project that you add to your solution that will target your web project and when built will publish your web project as part of the build process. It makes it dirt simple to automatically build a site as part of build without mucking with MSBuild (though MSBuild isn't that difficult).

自动化包含在 Visual Studio 的“构建”菜单中可用的“发布”操作中的功能的最简单方法是使用Web 部署项目。VS2005 也有一个。基本上,这是一个额外的项目,您添加到您的解决方案中,该项目将针对您的 Web 项目,并且在构建时将发布您的 Web 项目作为构建过程的一部分。它使自动构建站点作为构建的一部分变得非常简单,而无需使用 MSBuild(尽管 MSBuild 并不难)。

回答by Luhmann

Well you could do it with MSBuildin a post-build event.

好吧,您可以在构建后事件中使用 MSBuild来完成。

But are you sure you want to do this? It will slow you down, and you probably don't need to publish for every build? Why not just run the site in IIS instead of Cassini.

但是你确定要这样做吗?它会减慢您的速度,而且您可能不需要为每个构建发布?为什么不直接在 IIS 中而不是在 Cassini 中运行该站点。

回答by Daeron

Step 1. Make sure that you have a web project.

步骤 1. 确保您有一个 Web 项目。

Step 2. Go to View->Toolbars->Web One Click Publish.

步骤 2. 转到查看->工具栏->Web 一键发布。

The publish button web button on the toolbar will do what you want... build and publish in one step.

工具栏上的发布按钮 Web 按钮将执行您想要的操作……一步构建和发布。

回答by Franci Penov

Here is how I do it in my web site project. Note that this will copy to a folder; if you want to publich through FTB, WebDav or SSH, you need to use the Exectask instead of the Copytask and specify a command-line tool that can deploy the files over the desired protocol.

这是我在我的网站项目中的做法。请注意,这将复制到一个文件夹;如果你想通过 FTB、WebDav 或 SSH 公开,你需要使用Exec任务而不是Copy任务并指定一个命令行工具,可以通过所需的协议部署文件。

Also, you can't edit the AfterBuildtask from the project settings in the VS IDE. You need to open it in Notepad or your favorite text/XML editor. (You could even use VS, if you close the solution and enforce it to open the file with the XML editor :-))

此外,您无法AfterBuild在 VS IDE 的项目设置中编辑任务。您需要在记事本或您喜欢的文本/XML 编辑器中打开它。(如果您关闭解决方案并强制它使用 XML 编辑器打开文件,您甚至可以使用 VS :-))

There's also a build target that invokes the AspNetCompiler, which I have currently turned off, but you could easily turn on through the MvcBuildViewsproperty value.

还有一个调用 的构建目标,AspNetCompiler我目前已将其关闭,但您可以通过MvcBuildViews属性值轻松打开。

  <PropertyGroup>
    <MvcBuildViews>false</MvcBuildViews>
    <DropPath>..\..\drop\</DropPath>
  </PropertyGroup>
  <Target Name="AfterBuildCompiler" Condition="'$(MvcBuildViews)'=='true'">
    <AspNetCompiler VirtualPath="temp" PhysicalPath="$(ProjectDir)" />
  </Target>
  <Target Name="AfterBuild" DependsOnTargets="AfterBuildCompiler">
    <ConvertToAbsolutePath Paths="$(DropPath)">
      <Output TaskParameter="AbsolutePaths" ItemName="FullDropPath" />
    </ConvertToAbsolutePath>
    <Message Importance="High" Text="Binplacing -&gt; @(FullDropPath)" />
    <ItemGroup>
      <Binaries Include="$(OutputPath)**\*.*" />
    </ItemGroup>
    <Copy SkipUnchangedFiles="True" SourceFiles="@(Compile)" DestinationFiles="@(Compile->'$(DropPath)%(Identity)')" />
    <Copy SkipUnchangedFiles="True" SourceFiles="@(Content)" DestinationFiles="@(Content->'$(DropPath)%(Identity)')" />
    <Copy SkipUnchangedFiles="True" SourceFiles="@(EntityDeploy)" DestinationFiles="@(EntityDeploy->'$(DropPath)%(Identity)')" />
    <Copy SkipUnchangedFiles="True" SourceFiles="@(Binaries)" DestinationFiles="@(Binaries->'$(DropPath)%(Identity)')" />
  </Target>

回答by Ian Mercer

Option 1: Switch from Cruise Control to JetBrains TeamCity (you won't regret it!). In TeamCity there's an Artifacts option which ...

选项 1:从 Cruise Control 切换到 JetBrains TeamCity(您不会后悔的!)。在 TeamCity 中,有一个 Artifacts 选项...

"Artifacts are files produced by a build. After finishing a build, TeamCity searches for artifacts in the build's checkout directory according to the specified artifact patterns. Matching files are then uploaded to the server, where they become available for download."

“工件是由构建生成的文件。完成构建后,TeamCity 根据指定的工件模式在构建的检出目录中搜索工件。然后将匹配的文件上传到服务器,在那里它们可供下载。”

Option 2: Create a task in Cruise Control to do an XCOPY after the build is complete.

选项 2:在 Cruise Control 中创建任务以在构建完成后执行 XCOPY。

<tasks>
    <msbuild>
       ... here's your main build ...
    </msbuild>

  <exec>
    ... define your XCOPY or other executable task here ...
    <buildTimeoutSeconds>900</buildTimeoutSeconds>
  </exec>

Option 3: Create a post-build project in your solution and have a task in it to copy the files over, add a condition on that task that to only trigger when running on cruise control (various environment variables enable this).

选项 3:在您的解决方案中创建一个构建后项目,并在其中创建一个任务来复制文件,在该任务上添加一个条件,该条件仅在巡航控制上运行时触发(各种环境变量启用此功能)。