使用 NAnt 发布 WebApplication

发布于 2024-07-16 07:24:34 字数 78 浏览 3 评论 0原文

是否可以使用 NAnt 在解决方案上完成发布(如在 Visual Studio 中在 Web 应用程序项目上发布)? 我只是找不到解决方案。

Is it possible to accomplish publish (as in Visual Studio publish on Web Application project) on solution using NAnt? I just can't find the solution.

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

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

发布评论

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

评论(4

各空 2024-07-23 07:24:34

它们的关键是使用内置的“_CopyWebApplication”目标。

这是我

<target name="compile" description="Compiles the project.">
        <exec basedir="." program="${DotNetPath}msbuild.exe" commandline=" src/MyProject.Web/MyProject.Web.csproj /nologo 
  /t:Rebuild
  /t:ResolveReferences;_CopyWebApplication
  /p:OutDir=../../output/build/bin/
  /p:WebProjectOutputDir=../../output/build/
  /p:Debug=${debug}
  /p:Configuration=${configuration}
  /v:m"
    workingdir="." failonerror="true" />
    </target>

对以下目录结构所做的操作:

/project.build
/src/myprojct.sln
/src/myporject.web/myproject.web.csproj
/output

编辑:我还使用它来使用 YUI 压缩来压缩我的 css 和 js

<target name="compress-js">
        <foreach item="File" property="filename">
            <in>
                <items basedir="output/build/assets/javascript/">
                    <include name="/**/*.js" />
                    <exclude name="/**/*.min.js" />
                    <exclude name="/**/*.pack.js" />
                </items>
            </in>
            <do>
                <exec basedir="." program="${JavaPath}java" commandline=" -jar S:\yuicompressor-2.4.1\build\yuicompressor-2.4.1.jar --type js --charset utf-8 -o "${filename}" "${filename}"" failonerror="true" />
            </do>
        </foreach>
    </target>


    <target name="compress-css" depends="combine-css">
        <foreach item="File" property="filename">
            <in>
                <items basedir="output/build/assets/css/">
                    <include name="/**/*.css" />
                    <exclude name="/**/*.min.css" />
                    <exclude name="/**/*.pack.css" />
                </items>
            </in>
            <do>
                <exec basedir="." program="S:\Java\jdk1.6.0_11\bin\java" commandline=" -jar S:\yuicompressor-2.4.1\build\yuicompressor-2.4.1.jar --type css --charset utf-8 -o "${filename}" "${filename}"" failonerror="true" />
            </do>
        </foreach>
    </target>

They key is to use the built-in "_CopyWebApplication" target.

Here is what i do

<target name="compile" description="Compiles the project.">
        <exec basedir="." program="${DotNetPath}msbuild.exe" commandline=" src/MyProject.Web/MyProject.Web.csproj /nologo 
  /t:Rebuild
  /t:ResolveReferences;_CopyWebApplication
  /p:OutDir=../../output/build/bin/
  /p:WebProjectOutputDir=../../output/build/
  /p:Debug=${debug}
  /p:Configuration=${configuration}
  /v:m"
    workingdir="." failonerror="true" />
    </target>

with the dir structure of:

/project.build
/src/myprojct.sln
/src/myporject.web/myproject.web.csproj
/output

Edit: i also use this to use the YUI compression to compress my css and js

<target name="compress-js">
        <foreach item="File" property="filename">
            <in>
                <items basedir="output/build/assets/javascript/">
                    <include name="/**/*.js" />
                    <exclude name="/**/*.min.js" />
                    <exclude name="/**/*.pack.js" />
                </items>
            </in>
            <do>
                <exec basedir="." program="${JavaPath}java" commandline=" -jar S:\yuicompressor-2.4.1\build\yuicompressor-2.4.1.jar --type js --charset utf-8 -o "${filename}" "${filename}"" failonerror="true" />
            </do>
        </foreach>
    </target>


    <target name="compress-css" depends="combine-css">
        <foreach item="File" property="filename">
            <in>
                <items basedir="output/build/assets/css/">
                    <include name="/**/*.css" />
                    <exclude name="/**/*.min.css" />
                    <exclude name="/**/*.pack.css" />
                </items>
            </in>
            <do>
                <exec basedir="." program="S:\Java\jdk1.6.0_11\bin\java" commandline=" -jar S:\yuicompressor-2.4.1\build\yuicompressor-2.4.1.jar --type css --charset utf-8 -o "${filename}" "${filename}"" failonerror="true" />
            </do>
        </foreach>
    </target>
无悔心 2024-07-23 07:24:34

使用 MSBuild 胜过了使用 NAnt 的目的,NAnt 是替代 MSBuild 的东西,使用下面的代码对 Web 应用程序项目进行干净的 NAnt 编译,就像在 VS 2003/2005/2008 中一样。

这个对我有用!

<?xml version="1.0"?>
<project name="MyTest" default="run">
    <property name="basename" value="MyTest1x"/>
    <property name="debug" value="false"/>
    <property name="copytarget" value="c:\temp"/>

    <target name="clean">
        <delete>
            <fileset basedir="${copytarget}">
                <include name="bin/${basename}.dll"/>
                <include name="**/*.???x"/>
                <include name="Web.config"/>
            </fileset>
        </delete>
    </target>

    <target name="build">
        <mkdir dir="${copytarget}/bin" />
        <csc target="library" output="${copytarget}/bin/${basename}.dll" >
            <sources>
                <include name="*.cs"/>
            </sources>
        </csc>
    </target>

    <target name="run" depends="clean,build">
    <copy todir="${copytarget}" overwrite="true">
      <fileset basedir=".">
             <include name="**/*.???x" />
             <include name="Web.config" />
          </fileset>
       </copy>
   </target>
</project>

Using MSBuild beats the purpose of using NAnt, NAnt is something that replaces MSBuild, use the below to do a clean NAnt compilation of Web Application Projects as in VS 2003/2005/2008.

It works for me!

<?xml version="1.0"?>
<project name="MyTest" default="run">
    <property name="basename" value="MyTest1x"/>
    <property name="debug" value="false"/>
    <property name="copytarget" value="c:\temp"/>

    <target name="clean">
        <delete>
            <fileset basedir="${copytarget}">
                <include name="bin/${basename}.dll"/>
                <include name="**/*.???x"/>
                <include name="Web.config"/>
            </fileset>
        </delete>
    </target>

    <target name="build">
        <mkdir dir="${copytarget}/bin" />
        <csc target="library" output="${copytarget}/bin/${basename}.dll" >
            <sources>
                <include name="*.cs"/>
            </sources>
        </csc>
    </target>

    <target name="run" depends="clean,build">
    <copy todir="${copytarget}" overwrite="true">
      <fileset basedir=".">
             <include name="**/*.???x" />
             <include name="Web.config" />
          </fileset>
       </copy>
   </target>
</project>
心不设防 2024-07-23 07:24:34

我知道这是一个老问题,但我刚刚学到了一些东西,所以我决定分享:虽然“_CopyWebApplication”目标存在并工作是 100% 真实的,但从 .NET 4.0 开始,它已被“ Microsoft.Web.Publishing.targets 中的“_WPPCopyWebApplication”目标,它支持 web.config 转换语法等新功能

(重新发布到所有类似措辞的问题,所以不要投票给这个:))

I know this is an old question, but I just learned something, so I decided I'd share: While it is 100% true that the "_CopyWebApplication" target exists and works, as of .NET 4.0 it has been superseded by the "_WPPCopyWebApplication" target in Microsoft.Web.Publishing.targets, which supports new features like web.config transformation syntax, etc.

(reposting to all the similarly worded questions, so don't vote for this one :) )

情话已封尘 2024-07-23 07:24:34

以下是使用 nant 的 MSBUILD 任务执行此操作的方法:

<property name="debug" value="AutomatedDebug" />
<property name="configuration" value="Debug;TargetFrameworkVersion=v3.5" />

    <msbuild project="src\WebApplication1\WebApplication1.csproj" failonerror="true">
      <arg value="/nologo" />
      <arg value="/t:Rebuild" />
      <arg value="/t:ResolveReferences;_CopyWebApplication" />
      <arg value="/p:OutDir=../../build/Debug/WebApplication/" />
      <arg value="/p:WebProjectOutputDir=../../build/Debug/WebApplication-Deploy/" />
      <arg value="/p:Debug=${debug}" />
      <arg value="/p:Configuration=${configuration}" />
      <arg value="/v:m" />
    </msbuild>

这会将 WebApplication 编译到可部署的文件夹中,就像使用 Visual Studio 中的“发布”功能一样。

Here is how you can do it using the MSBUILD task for nant:

<property name="debug" value="AutomatedDebug" />
<property name="configuration" value="Debug;TargetFrameworkVersion=v3.5" />

    <msbuild project="src\WebApplication1\WebApplication1.csproj" failonerror="true">
      <arg value="/nologo" />
      <arg value="/t:Rebuild" />
      <arg value="/t:ResolveReferences;_CopyWebApplication" />
      <arg value="/p:OutDir=../../build/Debug/WebApplication/" />
      <arg value="/p:WebProjectOutputDir=../../build/Debug/WebApplication-Deploy/" />
      <arg value="/p:Debug=${debug}" />
      <arg value="/p:Configuration=${configuration}" />
      <arg value="/v:m" />
    </msbuild>

This will compile the WebApplication into a deployable folder, just like using the "Publish" feature from within Visual Studio.

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