How to invoke MSBuild via command prompt?

牧云@^-^@ 提交于 2019-11-29 11:05:16

问题


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.


回答1:


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.




回答2:


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).




回答3:


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.



来源:https://stackoverflow.com/questions/5854905/how-to-invoke-msbuild-via-command-prompt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!