pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

如何使用 msbuild 發布網頁?

How to Publish Web with msbuild?(如何使用 msbuild 發布網頁?)
本文介紹了如何使用 msbuild 發布網頁?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

Visual Studio 2010 有一個發布命令,允許您將 Web 應用程序項目發布到文件系統位置.我想在我的 TeamCity 構建服務器上執行此操作,因此我需要使用解決方案運行程序或 msbuild 執行此操作.我嘗試使用 Publish 目標,但我認為這可能適用于 ClickOnce:

msbuild Project.csproj/t:Publish/p:Configuration=Deploy

我基本上想做一個 Web 部署項目所做的事情,但沒有插件.我需要它來編譯 WAP,刪除任何不需要執行的文件,執行任何 web.xml 文件.配置轉換,并將輸出復制到指定位置.

我的解決方案,基于 Jeff Siver 的回答

<Target Name="Deploy"><MSBuild Projects="$(SolutionFile)"屬性="配置=$(配置);DeployOnBuild=true;DeployTarget=Package"ContinueOnError="假"/><Exec Command="&quot;$(ProjectPath)obj$(Configuration)Package$(ProjectName).deploy.cmd&quot;/y/m:$(DeployServer) -enableRule:DoNotDeleteRule"ContinueOnError="假"/></目標>

解決方案

我得到它主要是在沒有自定義 msbuild 腳本的情況下工作.以下是相關的 TeamCity 構建配置設置:

<上一頁>工件路徑:%system.teamcity.build.workingDir%MyProjectobjDebugPackagePackageTmp運行器類型:MSBuild(用于 MSBuild 文件的運行器)構建文件路徑:MyProjectMyProject.csproj工作目錄:與結帳目錄相同MSBuild 版本:Microsoft .NET Framework 4.0MSBuild 工具版本:4.0運行平臺:x86目標:包MSBuild.exe 的命令行參數:/p:Configuration=Debug

這將編譯、打包(使用 web.config 轉換)并將輸出保存為工件.唯一缺少的是將輸出復制到指定位置,但這可以在另一個帶有工件依賴項的 TeamCity 構建配置或使用 msbuild 腳本中完成.

更新

這是一個 msbuild 腳本,它將編譯、打包(使用 web.config 轉換)并將輸出復制到我的登臺服務器

<?xml version="1.0" encoding="utf-8" ?><Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><屬性組><配置條件="'$(Configuration)' == ''">發布</配置><解決方案名稱>我的解決方案</解決方案名稱><SolutionFile>$(SolutionName).sln</SolutionFile><項目名稱>我的項目</項目名稱><ProjectFile>$(ProjectName)$(ProjectName).csproj</ProjectFile></屬性組><目標名稱="Build" DependsOnTargets="BuildPackage;CopyOutput"/><目標名稱="BuildPackage"><MSBuild Projects="$(SolutionFile)" ContinueOnError="false" Targets="Rebuild" Properties="Configuration=$(Configuration)"/><MSBuild Projects="$(ProjectFile)" ContinueOnError="false" Targets="Package" Properties="Configuration=$(Configuration)"/></目標><目標名稱="復制輸出"><項目組><PackagedFiles Include="$(ProjectName)obj$(Configuration)PackagePackageTmp***.*"/></項目組><Copy SourceFiles="@(PackagedFiles)" DestinationFiles="@(PackagedFiles->'\build02wwwroot$(ProjectName)$(Configuration)\%(RecursiveDir)%(Filename)%(Extension)')"/></目標></項目>

您還可以從 PropertyGroup 標記中刪除 SolutionName 和 ProjectName 屬性并將它們傳遞給 msbuild.

msbuild build.xml/p:Configuration=Deploy;SolutionName=MySolution;ProjectName=MyProject

更新 2

由于這個問題仍然有大量流量,我認為值得用我當前使用 Web 部署(也稱為 MSDeploy).

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build" ToolsVersion="4.0"><屬性組><配置條件="'$(Configuration)' == ''">發布</配置><ProjectFile Condition="'$(ProjectFile)' == ''">$(ProjectName)$(ProjectName).csproj</ProjectFile><DeployServiceUrl 條件="'$(DeployServiceUrl)' == ''">http://staging-server/MSDeployAgentService</DeployServiceUrl></屬性組><目標名稱="驗證屬性"><!-- 驗證我們是否具有所有必需屬性的值--><錯誤條件="'$(ProjectName)' == '' " Text="ProjectName 是必需的."/></目標><目標名稱="構建" DependsOnTargets="VerifyProperties"><!-- 使用windows身份驗證部署--><MSBuild Projects="$(ProjectFile)"屬性=配置=$(配置);MvcBuildViews=假;部署構建=真;部署目標=MSDeployPublish;CreatePackageOnPublish=真;AllowUntrustedCertificate=True;MSDeployPublishMethod=遠程代理;MsDeployServiceUrl=$(DeployServiceUrl);SkipExtraFilesOnServer=真;用戶名=;密碼=;"ContinueOnError="假"/></目標></項目>

在 TeamCity 中,我有名為 env.Configurationenv.ProjectNameenv.DeployServiceUrl 的參數.MSBuild 運行器具有構建文件路徑,并且參數自動傳遞(您不必在命令行參數中指定它們).

你也可以從命令行運行它:

msbuild build.xml/p:Configuration=Staging;ProjectName=MyProject;DeployServiceUrl=http://staging-server/MSDeployAgentService

Visual Studio 2010 has a Publish command that allows you to publish your Web Application Project to a file system location. I'd like to do this on my TeamCity build server, so I need to do it with the solution runner or msbuild. I tried using the Publish target, but I think that might be for ClickOnce:

msbuild Project.csproj /t:Publish /p:Configuration=Deploy

I basically want to do exactly what a web deployment project does, but without the add-in. I need it to compile the WAP, remove any files unnecessary for execution, perform any web.config transformations, and copy the output to a specified location.

My Solution, based on Jeff Siver's answer

<Target Name="Deploy">
    <MSBuild Projects="$(SolutionFile)" 
             Properties="Configuration=$(Configuration);DeployOnBuild=true;DeployTarget=Package" 
             ContinueOnError="false" />
    <Exec Command="&quot;$(ProjectPath)obj$(Configuration)Package$(ProjectName).deploy.cmd&quot; /y /m:$(DeployServer) -enableRule:DoNotDeleteRule" 
          ContinueOnError="false" />
</Target>

解決方案

I got it mostly working without a custom msbuild script. Here are the relevant TeamCity build configuration settings:

Artifact paths: %system.teamcity.build.workingDir%MyProjectobjDebugPackagePackageTmp 
Type of runner: MSBuild (Runner for MSBuild files) 
Build file path: MyProjectMyProject.csproj 
Working directory: same as checkout directory 
MSBuild version: Microsoft .NET Framework 4.0 
MSBuild ToolsVersion: 4.0 
Run platform: x86 
Targets: Package 
Command line parameters to MSBuild.exe: /p:Configuration=Debug

This will compile, package (with web.config transformation), and save the output as artifacts. The only thing missing is copying the output to a specified location, but that could be done either in another TeamCity build configuration with an artifact dependency or with an msbuild script.

Update

Here is an msbuild script that will compile, package (with web.config transformation), and copy the output to my staging server

<?xml version="1.0" encoding="utf-8" ?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
        <SolutionName>MySolution</SolutionName>
        <SolutionFile>$(SolutionName).sln</SolutionFile>
        <ProjectName>MyProject</ProjectName>
        <ProjectFile>$(ProjectName)$(ProjectName).csproj</ProjectFile>
    </PropertyGroup>

    <Target Name="Build" DependsOnTargets="BuildPackage;CopyOutput" />

    <Target Name="BuildPackage">
        <MSBuild Projects="$(SolutionFile)" ContinueOnError="false" Targets="Rebuild" Properties="Configuration=$(Configuration)" />
        <MSBuild Projects="$(ProjectFile)" ContinueOnError="false" Targets="Package" Properties="Configuration=$(Configuration)" />
    </Target>

    <Target Name="CopyOutput">
        <ItemGroup>
            <PackagedFiles Include="$(ProjectName)obj$(Configuration)PackagePackageTmp***.*"/>
        </ItemGroup>
        <Copy SourceFiles="@(PackagedFiles)" DestinationFiles="@(PackagedFiles->'\build02wwwroot$(ProjectName)$(Configuration)\%(RecursiveDir)%(Filename)%(Extension)')"/>
    </Target>
</Project>

You can also remove the SolutionName and ProjectName properties from the PropertyGroup tag and pass them to msbuild.

msbuild build.xml /p:Configuration=Deploy;SolutionName=MySolution;ProjectName=MyProject

Update 2

Since this question still gets a good deal of traffic, I thought it was worth updating my answer with my current script that uses Web Deploy (also known as MSDeploy).

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build" ToolsVersion="4.0">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
    <ProjectFile Condition=" '$(ProjectFile)' == '' ">$(ProjectName)$(ProjectName).csproj</ProjectFile>
    <DeployServiceUrl Condition=" '$(DeployServiceUrl)' == '' ">http://staging-server/MSDeployAgentService</DeployServiceUrl>
  </PropertyGroup>

  <Target Name="VerifyProperties">
    <!-- Verify that we have values for all required properties -->
    <Error Condition=" '$(ProjectName)' == '' " Text="ProjectName is required." />
  </Target>

  <Target Name="Build" DependsOnTargets="VerifyProperties">
    <!-- Deploy using windows authentication -->
    <MSBuild Projects="$(ProjectFile)"
             Properties="Configuration=$(Configuration);
                             MvcBuildViews=False;
                             DeployOnBuild=true;
                             DeployTarget=MSDeployPublish;
                             CreatePackageOnPublish=True;
                             AllowUntrustedCertificate=True;
                             MSDeployPublishMethod=RemoteAgent;
                             MsDeployServiceUrl=$(DeployServiceUrl);
                             SkipExtraFilesOnServer=True;
                             UserName=;
                             Password=;"
             ContinueOnError="false" />
  </Target>
</Project>

In TeamCity, I have parameters named env.Configuration, env.ProjectName and env.DeployServiceUrl. The MSBuild runner has the build file path and the parameters are passed automagically (you don't have to specify them in Command line parameters).

You can also run it from the command line:

msbuild build.xml /p:Configuration=Staging;ProjectName=MyProject;DeployServiceUrl=http://staging-server/MSDeployAgentService

這篇關于如何使用 msbuild 發布網頁?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Is there a way to know if someone has bookmarked your website?(有沒有辦法知道是否有人為您的網站添加了書簽?)
Determining an #39;active#39; user count of an ASP.NET site(確定 ASP.NET 站點的“活動用戶數)
Best way to keep track of current online users(跟蹤當前在線用戶的最佳方式)
Publish one web project from solution with msbuild(使用 msbuild 從解決方案發布一個 Web 項目)
#39;dotnet restore#39; vs. #39;nuget restore#39; with TeamCity(使用 TeamCity 的“dotnet restore與“nuget restore)
Could not load file or assembly #39;Microsoft.Build.Framework#39;(VS 2017)(無法加載文件或程序集“Microsoft.Build.Framework(VS 2017))
主站蜘蛛池模板: 【星耀裂变】_企微SCRM_任务宝_视频号分销裂变_企业微信裂变增长_私域流量_裂变营销 | 壹作文_中小学生优秀满分作文大全 | 蒜肠网-动漫,二次元,COSPLAY,漫展以及收藏型模型,手办,玩具的新媒体.(原变形金刚变迷TF圈) | 回收二手冲床_金丰旧冲床回收_协易冲床回收 - 大鑫机械设备 | 复合土工膜厂家|hdpe防渗土工膜|复合防渗土工布|玻璃纤维|双向塑料土工格栅-安徽路建新材料有限公司 | 恒压供水控制柜|无负压|一体化泵站控制柜|PLC远程调试|MCGS触摸屏|自动控制方案-联致自控设备 | 智能交通网_智能交通系统_ITS_交通监控_卫星导航_智能交通行业 | 披萨石_披萨盘_电器家电隔热绵加工定制_佛山市南海区西樵南方综合保温材料厂 | 陶瓷砂磨机,盘式砂磨机,棒销式砂磨机-无锡市少宏粉体科技有限公司 | 大倾角皮带机-皮带输送机-螺旋输送机-矿用皮带输送机价格厂家-河南坤威机械 | 电采暖锅炉_超低温空气源热泵_空气源热水器-鑫鲁禹电锅炉空气能热泵厂家 | 【星耀裂变】_企微SCRM_任务宝_视频号分销裂变_企业微信裂变增长_私域流量_裂变营销 | 超声骨密度仪-动脉硬化检测仪器-人体成分分析仪厂家/品牌/价格_南京科力悦 | 微动开关厂家-东莞市德沃电子科技有限公司| 骨龄仪_骨龄检测仪_儿童骨龄测试仪_品牌生产厂家【品源医疗】 | 聚天冬氨酸,亚氨基二琥珀酸四钠,PASP,IDS - 远联化工 | 全自动端子机|刺破式端子压接机|全自动双头沾锡机|全自动插胶壳端子机-东莞市傅氏兄弟机械设备有限公司 | 浇注料-高铝砖耐火砖-郑州凯瑞得窑炉耐火材料有限公司 | 新型游乐设备,360大摆锤游乐设备「诚信厂家」-山东方鑫游乐设备 新能源汽车电池软连接,铜铝复合膜柔性连接,电力母排-容发智能科技(无锡)有限公司 | 超声波破碎仪-均质乳化机(供应杭州,上海,北京,广州,深圳,成都等地)-上海沪析实业有限公司 | 电子元器件呆滞料_元器件临期库存清仓尾料_尾料优选现货采购处理交易商城 | 分轨 | 上传文件,即刻分离人声和伴奏 | 模型公司_模型制作_沙盘模型报价-中国模型网| 车间除尘设备,VOCs废气处理,工业涂装流水线,伸缩式喷漆房,自动喷砂房,沸石转轮浓缩吸附,机器人喷粉线-山东创杰智慧 | 塑料撕碎机_编织袋撕碎机_废纸撕碎机_生活垃圾撕碎机_废铁破碎机_河南鑫世昌机械制造有限公司 | 空气能采暖,热泵烘干机,空气源热水机组|设备|厂家,东莞高温热泵_正旭新能源 | GEDORE扭力螺丝刀-GORDON防静电刷-CHEMTRONICS吸锡线-上海卓君电子有限公司 | 武汉刮刮奖_刮刮卡印刷厂_为企业提供门票印刷_武汉合格证印刷_现金劵代金券印刷制作 - 武汉泽雅印刷有限公司 | 暴风影音| 次氯酸钠厂家,涉水级次氯酸钠,三氯化铁生产厂家-淄博吉灿化工 | 代理记账_公司起名核名_公司注册_工商注册-睿婕实业有限公司 | 传爱自考网_传爱自学考试网 | 合肥网带炉_安徽箱式炉_钟罩炉-合肥品炙装备科技有限公司 | 陶瓷砂磨机,盘式砂磨机,棒销式砂磨机-无锡市少宏粉体科技有限公司 | 广东恩亿梯电源有限公司【官网】_UPS不间断电源|EPS应急电源|模块化机房|电动汽车充电桩_UPS电源厂家(恩亿梯UPS电源,UPS不间断电源,不间断电源UPS) | 400电话_400电话申请_888元包年_400电话办理服务中心_400VIP网 | 阻垢剂,反渗透阻垢剂,缓蚀阻垢剂-山东普尼奥水处理科技有限公司 真空粉体取样阀,电动楔式闸阀,电动针型阀-耐苛尔(上海)自动化仪表有限公司 | 影视模板素材_原创专业影视实拍视频素材-8k像素素材网 | 免费个人pos机申请办理-移动pos机刷卡-聚合收款码办理 | 真空包装机-诸城市坤泰食品机械有限公司 | 螺杆泵_中成泵业|