如何通过命令提示符调用 MSBuild?

发布于 2024-11-04 16:34:59 字数 211 浏览 0 评论 0原文

我有一个网站(不是 Web 应用程序),我想每天晚上从同一目录中的命令提示符发布它。

我不想使用 TeamCity、TFS 等构建自动化工具或 Nant 等第三方工具 - 应该使用 MSBuild 来完成。我该怎么做?

更新:在“发布”窗口中,唯一应检查的选项是使用固定命名和单页程序集

I have a website (not a web application) and I want to publish it from the command prompt in the same directory every night.

I don't want to use build automation tools like TeamCity, TFS, or third-party tools like Nant - it should be done with MSBuild. How can I do this?

Update: in the Publish window the only option that should be checked is Use Fixed naming and single page assemblies.

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

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

发布评论

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

评论(3

椒妓 2024-11-11 16:34:59

根据您的评论,您的 Web 项目是一个网站项目,而不是一个 Web 应用程序项目。

在这种情况下,“Publish”目标不能作为选项,但“AspNetCompiler”是解决方案。

创建一个包含以下内容的 xml 文件并从 MSBuild 调用它。

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="PrecompileWeb">
        <AspNetCompiler
            VirtualPath="/MyWebSite"
            PhysicalPath="c:\inetpub\wwwroot\MyWebSite\"
            TargetPath="c:\precompiledweb\MyWebSite\"
            Force="true"
            Debug="true"
            FixedNames="True"
        />
    </Target>
</Project>

此任务的参考位于此处,您可以配置所有取消/检查选项。

FixedName="True" 等于检查“使用固定命名和单页...”选项。

然后,您从 MSBuild 调用此文件而不是解决方案文件。

MSBuild your.xml /p:Configuration=<Debug/Release>

只要您的网站项目引用了您的类库,它们就会一起构建。

From your comment, your web project is a web site project and not a web application project.

In this case, 'Publish' target can not be the option but 'AspNetCompiler' is the solution.

Create an xml file with below content and call it from MSBuild.

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="PrecompileWeb">
        <AspNetCompiler
            VirtualPath="/MyWebSite"
            PhysicalPath="c:\inetpub\wwwroot\MyWebSite\"
            TargetPath="c:\precompiledweb\MyWebSite\"
            Force="true"
            Debug="true"
            FixedNames="True"
        />
    </Target>
</Project>

Reference to this task is here and you can configure all your un/check options.

FixedName="True" equals the checking of 'use fixed naming and single page...' option.

Then you call this file from MSBuild instead of the solution file.

MSBuild your.xml /p:Configuration=<Debug/Release>

As long as your class libraries are referenced by your web site project, they'll be built together.

奢华的一滴泪 2024-11-11 16:34:59
MSBuild.exe **MYPROJ**.sln 
/p:outdir="Z:\output\\",OutputPath="Z:\output\\",webprojectoutputdir="Z:\output\\",configuration=RELEASE 
/t:Clean;Build 

/flp1:logfile=Z:\output\\\Log_msbuild.log;verbosity=detailed 
/flp2:logfile=Z:\output\\\Log_warnings.log;warningsonly;verbosity=detailed 
/flp3:logfile=Z:\output\\\Log_errors.log;errorsonly;verbosity=detailed 

/nologo 
/noconlog

它可以编译所有类型的项目(Web、Web服务、桌面......),并且可以创建日志文件(构建日志、错误和警告)。

MSBuild.exe **MYPROJ**.sln 
/p:outdir="Z:\output\\",OutputPath="Z:\output\\",webprojectoutputdir="Z:\output\\",configuration=RELEASE 
/t:Clean;Build 

/flp1:logfile=Z:\output\\\Log_msbuild.log;verbosity=detailed 
/flp2:logfile=Z:\output\\\Log_warnings.log;warningsonly;verbosity=detailed 
/flp3:logfile=Z:\output\\\Log_errors.log;errorsonly;verbosity=detailed 

/nologo 
/noconlog

İt can compile all Types of projects(Web,webservice,desktop,..) and it can create log files as(buildlog,error and warnings).

墨离汐 2024-11-11 16:34:59

抱歉回复晚了,感谢艾伦的输入。不幸的是,您的建议不起作用,因此我最终执行了以下操作:

  • 在“构建默认值”选项卡下选择此构建不会将输出文件复制到放置文件夹
  • 使用“进程”选项卡下的默认模板
  • 选择AsConfigured 作为2 下输出位置 的值。在“进程”选项卡下构建
  • 使用此 MSBuild 参数字符串:

    /p:DeployOnBuild=True;DeployTarget=PipelinePreDeployCopyAllFilesToOneFolder;PackageTempRootDir="\\192.168.xx\Nightly\MainBranch";AutoParameterizationWebConfigConnectionStrings=false

此结果是我用作测试的 webroot 的以下文件夹地点: \\192.168.xx\Nightly\MainBranch\PackageTmp
这显然不是最佳选择,因为我不想拥有 PackageTmp 文件夹,而且我也没有测试当同一解决方案中有多个 Web 应用程序时会发生什么,但我不能使用更多时间在这个问题上。

我真的不明白为什么微软要把这么简单的任务搞得这么复杂。

Sorry for the late reply, and thanks for the input alan. Unfortunately your suggestion did not work so I ended up doing the following:

  • Choose This build does not copy output files to a drop folder under the Build defaults tab
  • Use the default template under the Process tab
  • Choose AsConfigured as the value for the Output location under 2. Build under the Process tab
  • Use this MSBuild argument string:

    /p:DeployOnBuild=True;DeployTarget=PipelinePreDeployCopyAllFilesToOneFolder;PackageTempRootDir="\\192.168.x.x\Nightly\MainBranch";AutoParameterizationWebConfigConnectionStrings=false

This result is the following folder which I use as the webroot for the test site: \\192.168.x.x\Nightly\MainBranch\PackageTmp.
This obviously isn't optimal since I would prefer not to have the PackageTmp folder and I also haven't tested what happens when there are multiple web applications in the same solution, but I can't use more time on this issue.

I really don't understand why Microsoft have made such a simple task so complicated.

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