复制VS2008“发布网站”从命令行

发布于 2024-11-16 18:06:31 字数 2136 浏览 2 评论 0原文

我试图在构建脚本中复制 Visual Studio 2008 中此对话的确切功能: 替代文本

这是一个 ASP.NET 网站站点,而不是网络应用程序

我在 Google 上搜索了这个问题,发现了很多涉及 MSBuild 的内容,但这似乎都与 ASP.NET Web 应用程序的解决方案有关:

http://www.driebier.net/post/Using-MSBuild-to-deploy-visual-studio-2005-web-applications.aspx http://blog.donnfelker.com/post/ TFS-Build-Not-Publishing-Web-Applications.aspx

这篇文章似乎与 ASP.NET 网站相关,但我发现在尝试使用这些建议构建时遇到错误:

C:\dev\T&A>msbuild /t:_CopyWebApplication /property:OutDir=c:\temp\taweb\ /prope
rty:WebProjectOutputDir=c:\temp\taweb\

Microsoft (R) Build Engine Version 3.5.30729.1
[Microsoft .NET Framework, Version 2.0.50727.3074]
Copyright (C) Microsoft Corporation 2007. All rights reserved.

Build started 22/04/2009 11:50:42.
Project "C:\dev\T&A\TAWeb.sln" on node 0 (_CopyWebApplication target(s)).
  Building solution configuration "Debug|.NET".
C:\dev\T&A\TAWeb.sln : error MSB4057: The target "_CopyWebApplication" does not
 exist in the project.
Done Building Project "C:\dev\T&A\TAWeb.sln" (_CopyWebApplication target(s)) --
 FAILED.


Build FAILED.

"C:\dev\T&A\TAWeb.sln" (_CopyWebApplication target) (1) ->
  C:\dev\T&A\TAWeb.sln : error MSB4057: The target "_CopyWebApplication" does n
ot exist in the project.

0 Warning(s)

1 Error(s)

Time Elapsed 00:00:00.06

我尝试发布的解决方案(继承的,不是我自己的)没有.csproj 文件(我可以从 C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets 导入 _CopyWebApplication 目标)

也许这是 Visual Studio 2005/2008 的差异?

不管怎样,我觉得我走错了路。

本质上,我只需要完全实现上述对话的功能,但是是从命令行实现的。

非常感谢

I am trying to replicate the exact functionality of this dialogue in Visual Studio 2008 in a build script:
alt text

This is an ASP.NET web site, not a web application.

I have Googled around this and turned up quite a bit of stuff involving MSBuild, but this all seems to concern solutions laid out as ASP.NET Web Applications:

http://www.driebier.net/post/Using-MSBuild-to-deploy-visual-studio-2005-web-applications.aspx
http://blog.donnfelker.com/post/TFS-Build-Not-Publishing-Web-Applications.aspx

This article seems to be relevant to ASP.NET Web Sites, but I find that I'm getting an error when trying to build using those suggestions:

C:\dev\T&A>msbuild /t:_CopyWebApplication /property:OutDir=c:\temp\taweb\ /prope
rty:WebProjectOutputDir=c:\temp\taweb\

Microsoft (R) Build Engine Version 3.5.30729.1
[Microsoft .NET Framework, Version 2.0.50727.3074]
Copyright (C) Microsoft Corporation 2007. All rights reserved.

Build started 22/04/2009 11:50:42.
Project "C:\dev\T&A\TAWeb.sln" on node 0 (_CopyWebApplication target(s)).
  Building solution configuration "Debug|.NET".
C:\dev\T&A\TAWeb.sln : error MSB4057: The target "_CopyWebApplication" does not
 exist in the project.
Done Building Project "C:\dev\T&A\TAWeb.sln" (_CopyWebApplication target(s)) --
 FAILED.


Build FAILED.

"C:\dev\T&A\TAWeb.sln" (_CopyWebApplication target) (1) ->
  C:\dev\T&A\TAWeb.sln : error MSB4057: The target "_CopyWebApplication" does n
ot exist in the project.

0 Warning(s)

1 Error(s)

Time Elapsed 00:00:00.06

The solution I'm trying to publish (inherited, not my own) doesn't have .csproj files (where I could import the _CopyWebApplication target from C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets)

Perhaps this is a Visual Studio 2005/2008 difference?

Anyway, I feel that I'm going down the wrong path there.

Essentially I just need to achieve exactly what the above dialogue does, but from the command line.

Thanks very much

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

请恋爱 2024-11-23 18:06:31

以下命令使用默认设置复制发布网站对话框。

使用默认设置发布网站的命令

aspnet_compiler -nologo -v / -p "C:\WebSite1" -u "C:\TargetPath"

参考

1) 请参阅社区内容标题为您想要发布一个网站,但您没有 Visual Studio...,位于 http://msdn.microsoft.com/en-us/library/20yh9f1b(经典).aspx

  • 微软 Visual Studio 2005 > Visual Studio 2005 命令提示符
  • Microsoft Visual Studio 2008 > Visual Studio 2008 命令提示
  • Microsoft .NET Framework SDK v2.0 > SDK 命令提示符

2) 请参阅 中的“ASP.NET 编译工具 (Aspnet_compiler.exe)” http://msdn.microsoft.com/en-us/library/ms229863.aspx

3) 以下摘自演练:使用 XCOPY 部署 ASP.NET Web 应用程序,网址为 http://msdn.microsoft.com/en-us/library/f735abw9.aspx

作为使用 XCOPY 的替代方法
命令行工具,支持
所有版本的 .NET Framework,
您可以使用新的.NET Framework 2.0
工具位于
%SystemRoot%\Microsoft.NET\Framework\版本
2 或更高版本
\Aspnet_compiler.exe 至
编译并部署您的 Web
应用。有关详细信息,请参阅ASP.NET 编译工具 (Aspnet_compiler.exe) .

4) 以下摘录自如何:预编译 ASP.NET 网站以进行部署,网址为 http://msdn.microsoft.com/en-us/library/ms227976.aspx

如果您的网站不是 Internet
信息服务 (IIS) 应用程序
因此在 IIS 中没有条目
配置数据库,使用以下值
-v 开关。

<代码>aspnet_compiler -p
物理或相对路径 -v /
目标路径

在这种情况下,
物理或相对路径参数
指的是完全合格的
网站所在的目录路径
文件所在位置,或相对路径
到当前目录。期间
(.) 运算符允许在
物理或相对路径参数。这
-v 开关指定编译器将用来解析的根
应用程序根引用(用于
例如,使用波形符 (~) 运算符)。
当您指定 / 的值时
编译器将使用 -v 开关
使用物理解析路径
路径作为根。

The following command duplicates the Publish Web Site dialog with default settings.

Command for Publish Web Site with Default Settings

aspnet_compiler -nologo -v / -p "C:\WebSite1" -u "C:\TargetPath"

Reference

1) See Community Content titled You want Publish a site but you have not Visual Studio then... at http://msdn.microsoft.com/en-us/library/20yh9f1b(classic).aspx.

  • Microsoft Visual Studio 2005 > Visual Studio 2005 Command Prompt
  • Microsoft Visual Studio 2008 > Visual Studio 2008 Command Prompt
  • Microsoft .NET Framework SDK v2.0 > SDK Command Prompt

2) See "ASP.NET Compilation Tool (Aspnet_compiler.exe)" at http://msdn.microsoft.com/en-us/library/ms229863.aspx.

3) Following excerpt from Walkthrough: Deploying an ASP.NET Web Application Using XCOPY at http://msdn.microsoft.com/en-us/library/f735abw9.aspx

As an alternative to using the XCOPY
command-line tool, which is supported
by all versions of the .NET Framework,
you can use the new .NET Framework 2.0
tool located at
%SystemRoot%\Microsoft.NET\Framework\version
2 or later
\Aspnet_compiler.exe to
compile and deploy your Web
application. For more information, see ASP.NET Compilation Tool (Aspnet_compiler.exe).

4) Following excerpt from How to: Precompile ASP.NET Web Sites for Deployment at http://msdn.microsoft.com/en-us/library/ms227976.aspx.

If your Web site is not an Internet
Information Services (IIS) application
and therefore has no entry in the IIS
metabase, used the following value for
the -v switch.

aspnet_compiler -p
physicalOrRelativePath -v /
targetPath

In this case, the
physicalOrRelativePath parameter
refers to the fully qualified
directory path in which the Web site
files are located, or a path relative
to the current directory. The period
(.) operator is allowed in the
physicalOrRelativePath parameter. The
-v switch specifies a root that the compiler will use to resolve
application-root references (for
example, with the tilde (~) operator).
When you specify the value of / for
the -v switch the compiler will
resolve the paths using the physical
path as the root.

所有深爱都是秘密 2024-11-23 18:06:31

我认为您正在寻找 AspNetCompiler 任务

<Target Name="PublishToIIS" DependsOnTargets="Publish">
    <AspNetCompiler    
            VirtualPath="$(IISVirtualPath)"
            TargetPath="$(IISTargetPath)"
            PhysicalPath="$(MSBuildProjectDirectory)/trunk/InternalAppCS/Web.UI/"
            Force="true"
            Debug="$(IISDebug)"
     />

</Target>

I think you are looking for the AspNetCompiler task

<Target Name="PublishToIIS" DependsOnTargets="Publish">
    <AspNetCompiler    
            VirtualPath="$(IISVirtualPath)"
            TargetPath="$(IISTargetPath)"
            PhysicalPath="$(MSBuildProjectDirectory)/trunk/InternalAppCS/Web.UI/"
            Force="true"
            Debug="$(IISDebug)"
     />

</Target>
时光清浅 2024-11-23 18:06:31

这种“神奇”的组合可以满足您的需求。 )只花了两天时间就为我的项目找到了正确的组合。)关键是包含 _CopyWebApplication 目标和 ResolveReferences 目标。

msbuild "/t:_CopyWebApplication;ResolveReferences;publish" /p:OutDir="C:\inetpub\wwwroot\[appname]\bin\" /p:WebProjectOutputDir="C:\inetpub\wwwroot\[appname]" c:\directory\[appname].csproj    

This "magic" combination does what you're looking for. )It only took two days to get the right combination for my project.) The key is to include the _CopyWebApplication target and the ResolveReferences target.

msbuild "/t:_CopyWebApplication;ResolveReferences;publish" /p:OutDir="C:\inetpub\wwwroot\[appname]\bin\" /p:WebProjectOutputDir="C:\inetpub\wwwroot\[appname]" c:\directory\[appname].csproj    
温柔一刀 2024-11-23 18:06:31

添加到您的 .csproj 文件:

<Target Name="AfterBuild">
<Message Text="Copying to Deployment Dir:" />
<Copy SourceFiles="@(Content)" DestinationFolder="..\PreCompiledWeb\%(Content.RelativeDir)" />
<CreateItem Include="$(OutputPath)\*">
    <Output TaskParameter="Include" ItemName="Binaries"/>
</CreateItem>
<Copy SourceFiles="@(Binaries)" DestinationFolder="..\PreCompiledWeb\bin" />

将“..\PreCompiledWeb”更改为要发布到的文件夹,或者您可以指定一个变量,例如: $(OutputFolder) 您可以传递该变量

,然后转到 Web 应用程序的文件夹并执行以下操作:

msbuild /t:Build

然后您可以将这些文件复制到任何位置想要使用 xcopy:

xcopy "..\PreCompiledWeb\*.*" "C:\MySite\" /e

应该可以。

Add to your .csproj file:

<Target Name="AfterBuild">
<Message Text="Copying to Deployment Dir:" />
<Copy SourceFiles="@(Content)" DestinationFolder="..\PreCompiledWeb\%(Content.RelativeDir)" />
<CreateItem Include="$(OutputPath)\*">
    <Output TaskParameter="Include" ItemName="Binaries"/>
</CreateItem>
<Copy SourceFiles="@(Binaries)" DestinationFolder="..\PreCompiledWeb\bin" />

Change "..\PreCompiledWeb" for the folder you want to publish to or you can specify a variable something like: $(OutputFolder) which you can pass

then go the folder of your webapplication and do:

msbuild /t:Build

Then you can copy those files wherever you want using xcopy:

xcopy "..\PreCompiledWeb\*.*" "C:\MySite\" /e

That should do it.

内心旳酸楚 2024-11-23 18:06:31

我个人使用 buildbot 来为我运行命令,我必须创建一个 VBS 脚本来为我执行上传。

我安装了 WinSCP 来执行 ftp 工作,然后编写上传脚本:

Set WshShell = CreateObject("WScript.Shell")
sCmd1 = """C:\Program Files\WinSCP\winscp.com"" <myusername> /command ""option batch on"" ""option confirm off"" ""put " & DefaultPath & strResult & "\" & DefaultFileName & " /Usr/<myuser>/" & updateType & "/" & strResult & "/"" ""exit"""

要从命令行预编译网站,我执行以下操作,但是我在网络服务器上执行此操作,而不是在上传之前执行此操作:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler -p "D:\<mycompany>\Backedup\Web Sites\<mysite\Root" -v /

Personally I use buildbot which runs commands for me, I had to create a VBS script which performs the upload for me.

I installed WinSCP to do the ftp work and then just scripted the upload:

Set WshShell = CreateObject("WScript.Shell")
sCmd1 = """C:\Program Files\WinSCP\winscp.com"" <myusername> /command ""option batch on"" ""option confirm off"" ""put " & DefaultPath & strResult & "\" & DefaultFileName & " /Usr/<myuser>/" & updateType & "/" & strResult & "/"" ""exit"""

To pre-compile the website from a command line I do the following, however I do this on the web server rather than before uploading it:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler -p "D:\<mycompany>\Backedup\Web Sites\<mysite\Root" -v /
被你宠の有点坏 2024-11-23 18:06:31

我一直在使用 msbuild 来实现你所描述的。您是否尝试过这样设置属性?

 /property:"OutDir=c:\temp\taweb\;WebProjectOutputDir=c:\temp\taweb\"

如果它仍然不起作用,请告诉我,我可以向您发送我的 bat 文件,该文件启动 msbuild 脚本,执行 svn get,构建 assembly.info 文件,部署网站,最后运行 http get在网站主页上,只是为了确保它正确构建和部署。

希望有帮助
日韩

I have been using msbuild for exactly what you describe. Have you tried setting the property like this?

 /property:"OutDir=c:\temp\taweb\;WebProjectOutputDir=c:\temp\taweb\"

If it still does not work, let me know and I can send you my bat file, that kicks of the msbuild script, that does the svn get, builds the assembly.info file, deploy the web site, and finally runs a http get on the site home page, just to make sure it built and deployed correctly.

Hope it helps
Rihan

2024-11-23 18:06:31

我正在努力解决同样的错误(MSB4057:项目中不存在目标“_CopyWebApplication”。

是的。我使用的是 Web 应用程序项目(而不是网站)。

我感到困惑,因为我有一个有效的项目,并且 没有。所以我坐下来比较了项目文件,我发现项目文件底部的构建目标部分是不同的。

一个 较新的另一个版本(不起作用)是几年前创建的,多年来已经升级到我正在使用的当前版本,升级后的项目显然没有使用新的构建目标进行升级。随着新版本的 Visual Studio 的推出,

在正在运行的项目文件的底部,我发现了以下内容:

<导入项目=“$(MSBuildBinPath)\Microsoft.VisualBasic.targets”/>

<导入项目="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v8.0\WebApplications\Microsoft.WebApplication.targets"/>

第二个导入行不在导致问题的项目中。

我只是从工作文件中复制导入,并将其粘贴到非工作文件中的相对位置,中提琴!

虽然这不是该线程中定义的初始问题的直接解决方案,但我希望这可以帮助其他一些偶然发现该线程、仅在实际 Web 应用程序项目中寻找类似问题的人。

I was struggling with the same error (MSB4057: The target "_CopyWebApplication" does not exist in the project.

Yes. I was using a Web Application Project (not a web site).

I was baffled because I had one project that worked, and one that did not. So I sat down with ExamDiffPro and went to work comparing the project files. What I found was the section of build target includes at the bottom of the project files were different.

One project (that was working) was created using a newer version of Visual Studio. The other one (that was NOT working) was created years ago and has been upgraded over the years, to the current version I am working with. The upgraded project, evidently didn't get upgraded with the new build targets as newer versions of Visual Studio became available.

At the bottom of the project file which was working, I found the following:

<Import Project="$(MSBuildBinPath)\Microsoft.VisualBasic.targets" />

<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v8.0\WebApplications\Microsoft.WebApplication.targets" />

The second import line was NOT in the project which was causing problems.

I simply copied the import from the working file, and pasted it in the relative location in the non-working file, and viola!

While this is not a direct solution to the initial problem defined in this thread, I hope this helps some of the other people that stumbled across this thread, looking for similar issues, only with actual Web Application Projects.

驱逐舰岛风号 2024-11-23 18:06:31

下面是一个小 PowerShell 脚本,它构建一个解决方案,然后从中发布一个 Web 项目。

MSBuild 适用于 .Net 3.5,因此如果需要,请更改为“\v4.0\”。

$build = "$env:windir\Microsoft.NET\Framework\v3.5\MSBuild.exe"

$SolutionPath = "C:\Projects\AdminWebSite"
$SolutionFile = "AdminWebSite.sln"
$WebProjectFile = "Admin.Web\Admin.Web.csproj"
$OutputPath = "C:\PublishedSites\Hosts\adminweb"

& $build "$SolutionPath\$SolutionFile" /t:rebuild
& $build "$SolutionPath\$WebProjectFile" "/t:ResolveReferences;_CopyWebApplication;publish" /p:OutDir="$OutputPath\bin\" /p:WebProjectOutputDir="$OutputPath"

“ResolveReferences”必须位于“_CopyWebApplication”之前,否则依赖项会丢失。

此处给出的示例路径构建为:

  • C:\Project\AdminWebSite\AdminWebSite.sln
  • C:\Project\AdminWebSite\Admin.Web\Admin.Web.csproj

Here's a little PowerShell script that builds a solution, then publishes a web project from it.

The MSBuild is for .Net 3.5, so change to "\v4.0\" if needed.

$build = "$env:windir\Microsoft.NET\Framework\v3.5\MSBuild.exe"

$SolutionPath = "C:\Projects\AdminWebSite"
$SolutionFile = "AdminWebSite.sln"
$WebProjectFile = "Admin.Web\Admin.Web.csproj"
$OutputPath = "C:\PublishedSites\Hosts\adminweb"

& $build "$SolutionPath\$SolutionFile" /t:rebuild
& $build "$SolutionPath\$WebProjectFile" "/t:ResolveReferences;_CopyWebApplication;publish" /p:OutDir="$OutputPath\bin\" /p:WebProjectOutputDir="$OutputPath"

The "ResolveReferences" must come before "_CopyWebApplication" otherwise dependencies go missing.

The example paths given here build to:

  • C:\Project\AdminWebSite\AdminWebSite.sln
  • C:\Project\AdminWebSite\Admin.Web\Admin.Web.csproj
ぶ宁プ宁ぶ 2024-11-23 18:06:31

您收到的错误(C:\dev\T&A\TAWeb.sln:错误 MSB4057:项目中不存在目标“_CopyWebApplication”)是由于两个问题造成的。首先:目标 _CopyWebApplication 必须在 WebApplication 项目文件上调用,而不是解决方案。第二:网站没有项目文件,WebApplications有项目文件。

_CopyWebApplication 目标仅适用于发布 WebApplication 项目。
使用 AspNetCompiler 必须使用 MSBuild 任务来发布网站。

当您在 Visual Studio 2008 中发布网站时,第二行输出是“预编译网站”。 Visual Studio 显示的选项用于将网站地图直接发布到 AspNetCompilerAspnet_compiler.exe

虽然我不是第一个在这里说“使用 AspNet_compiler”的人,但我认为描述原因可能会有所帮助。顺便说一句,我认为 AspNet_compiler 可用于发布 Web 应用程序,但我需要做更多测试。

The error you received (C:\dev\T&A\TAWeb.sln : error MSB4057: The target "_CopyWebApplication" does not exist in the project) is due to two issues. First: the target _CopyWebApplication must be called on a WebApplication project file, not a solution. Second: a website does not have a project file, WebApplications have project files.

The _CopyWebApplication target only applies to publishing a WebApplication project.
Use the AspNetCompiler MSBuild task must be used to publish a website.

When you publish a website in visual studio 2008, the second line of output is "Pre-compiling Web Site". The options visual studio displays for publishing a website map directly to options for the AspNetCompiler and Aspnet_compiler.exe.

Though I'm not the first here to say "use AspNet_compiler", I thought describing the reasons why may be helpful. On a side note, I think the AspNet_compiler can be used to publish a webapp but I need to do some more testing.

独享拥抱 2024-11-23 18:06:31

我使用 msbuild.exe(.net 3.5,vs 2008)的 bat 文件在文件夹中“发布”我的网站(vbproj)。

%msBuildDir%\msbuild
“D:\Project1\Client\WebPresentation\ConsultaOperaciones.vbproj”
/t:解析引用;重建
/p:BuildingProject=true;OutDir=D:\Instalaciones\ultima\PublicacionWeb\OutDir\;WebProjectOutputDir=D:\Instalaciones\ultima\PublicacionWeb\WebProjectDir\

I use bat file using msbuild.exe (.net 3.5, vs 2008) for "publish" my website (vbproj) in a folder.

%msBuildDir%\msbuild
"D:\Project1\Client\WebPresentation\ConsultaOperaciones.vbproj"
/t:ResolveReferences;Rebuild
/p:BuildingProject=true;OutDir=D:\Instalaciones\ultima\PublicacionWeb\OutDir\;WebProjectOutputDir=D:\Instalaciones\ultima\PublicacionWeb\WebProjectDir\

┼── 2024-11-23 18:06:31

“发布...”功能没有什么神奇之处,您无法自行重新创建,特别是因为您的目标是网络文件共享。

从本质上讲,它所做的就是将文件从一个地方复制到另一个地方。使用 NAnt,您可以通过 copy 任务来完成此任务或者您可以使用 exec 任务来调用 xcopy 如果您使用的是 NAnt 以外的构建工具,我当然有类似任务的支持。

如果您想保留原始代码和调试信息,可以排除以 .cs 或 .pdb 结尾的文件。 NAnt copy 和 xcopy 都提供了简单的方法来做到这一点。

There's nothing magical about the "Publish..." feature that you couldn't recreate on your own, especially since you are targeting a network file share.

At it's core, all it's doing is copying your files from one place to another. Using NAnt, you can pull this off with a copy task or you can use an exec task to call xcopy If you're using a build tool other than NAnt, I'm sure there is support for similar tasks.

If you want to leave your raw code and debugging information behind, you can exclude files that end with .cs or .pdb. Both NAnt copy and xcopy provide easy ways to do this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文