自动发布 Visual Studio 2010 功能?

发布于 2024-12-21 05:15:28 字数 520 浏览 0 评论 0原文

我读过一些关于自动化构建流程的好文章然而,我感兴趣的不仅仅是构建过程,而是发布。

我有几个使用基本模型的网站和服务。当我更改该模型时(这种情况不会经常发生),所有站点/服务都必须重新构建并发布到适当的目标目录(已包含在其配置中)。

所有项目文件夹都存在于一个文件夹中。

我正在考虑的方法是使用 MSBuild 从主文件夹运行脚本,并包含要构建/发布的项目的命名列表。

我在 此处 找到了一个关于为 MSBuild 创建构建脚本的好示例,但是,这个只满足一个项目的构建。

我如何让该过程遍历项目/目录的命名列表来执行相同的构建/发布脚本?

谢谢。

I've read a few good posts on automating build processes, however, what I'm interested in is not just a build process, but publishing.

I have several websites and services that use a base model. When I change that model (which won't happen very often), all sites/services will have to be rebuilt and published to their appropriate target directories (already contained in their config).

All project folders exist in one folder.

The approach I am considering is to use MSBuild to run a script from the the main folder, with a named list of projects to build/publish.

I have found a good example on creating a build script for MSBuild here, however, this only satisfies the build for one project.

How would I have the process go through a named list of projects/directories to perform the same build/publish script on?

Thanks.

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

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

发布评论

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

评论(3

月下凄凉 2024-12-28 05:15:28

最终的可重复使用的解决方案如下。

回顾:

我的根文件夹中有几个网站,其目录和项目文件名均以网站的值命名。我希望能够从命令行发布所有站点(或选定的列表) - 运行脚本。然后,这些网站将发布到我的 IIS 服务器目录。

首先,创建一个接受网站名称参数的 MSBuild 脚本:

<?xml version="1.0" encoding="utf-8" ?>
<Project DefaultTargets="Compile,Deploy" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <Target Name ="DeleteFiles">
    <Delete Files="..\$(ProjectName)\$(ProjectName)\obj\debug\$(ProjectName).dll"></Delete>
    <Delete Files="..\$(ProjectName)\$(ProjectName)\obj\release\$(ProjectName).dll"></Delete>
    <Delete Files="..\$(ProjectName)\$(ProjectName)\bin\$(ProjectName).dll"></Delete>
    <Delete Files="..\$(ProjectName)\$(ProjectName)\bin\$(ProjectName).pdb"></Delete>
  </Target>

  <Target Name="Compile" DependsOnTargets="DeleteFiles">
    <MSBuild Projects="..\$(ProjectName)\$(ProjectName)\$(ProjectName).csproj"
      Targets="Clean;Build"
      Properties="OutputPath=..\$(ProjectName)\bin"/>
  </Target>

  <Target Name="Deploy" DependsOnTargets="Compile">
    <MSBuild Projects="..\$(ProjectName)\$(ProjectName)\$(ProjectName).csproj"
        Targets="ResolveReferences;_CopyWebApplication"
        Properties="OutDir=C:\inetpub\wwwroot\$(ProjectName)\bin\;WebProjectOutputDir=C:\inetpub\wwwroot\$(ProjectName)" />
  </Target>

</Project>

接下来,创建一个文本文件,每行一个网站名称。这可以通过执行“dir >sites.txt”然后列编辑多余的内容来轻松生成。

IE。

site1.com
site2.com
site3.com
site4.com

最后,创建一个批处理文件,该文件循环访问 site.txt 中包含的列表,并执行 MSBuild 脚本:

@echo --------------------------------------------
@echo --  Iterating through list in sites.txt  --
@echo --------------------------------------------
for /f %%X in (sites.txt) do msbuild build.xml /p:ProjectName="%%X" /v:n

此解决方案驻留在与根目录中的其余网站处于同一级别的目录中,这就是为什么“..构建脚本中的 \$(ProjectName)"。

发布一堆网站的好方法,希望这对某人有帮助。

The final, reusable solution is as follows.

Recap:

I have several sites in a root folder who's directories and project file names are all named the value of the website. I want to be able to publish all sites (or a selected list) from the command line - running a script. The websites are then to be published to my IIS server directories.

First, create a MSBuild script that takes in the parameter of the website name:

<?xml version="1.0" encoding="utf-8" ?>
<Project DefaultTargets="Compile,Deploy" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <Target Name ="DeleteFiles">
    <Delete Files="..\$(ProjectName)\$(ProjectName)\obj\debug\$(ProjectName).dll"></Delete>
    <Delete Files="..\$(ProjectName)\$(ProjectName)\obj\release\$(ProjectName).dll"></Delete>
    <Delete Files="..\$(ProjectName)\$(ProjectName)\bin\$(ProjectName).dll"></Delete>
    <Delete Files="..\$(ProjectName)\$(ProjectName)\bin\$(ProjectName).pdb"></Delete>
  </Target>

  <Target Name="Compile" DependsOnTargets="DeleteFiles">
    <MSBuild Projects="..\$(ProjectName)\$(ProjectName)\$(ProjectName).csproj"
      Targets="Clean;Build"
      Properties="OutputPath=..\$(ProjectName)\bin"/>
  </Target>

  <Target Name="Deploy" DependsOnTargets="Compile">
    <MSBuild Projects="..\$(ProjectName)\$(ProjectName)\$(ProjectName).csproj"
        Targets="ResolveReferences;_CopyWebApplication"
        Properties="OutDir=C:\inetpub\wwwroot\$(ProjectName)\bin\;WebProjectOutputDir=C:\inetpub\wwwroot\$(ProjectName)" />
  </Target>

</Project>

Next, create a text file with one website name per line. This can be easily generated by doing a "dir > sites.txt" then column editing out superfluous content.

ie.

site1.com
site2.com
site3.com
site4.com

Lastly, create a batch file that iterates through the list contained in sites.txt, and executes the MSBuild script:

@echo --------------------------------------------
@echo --  Iterating through list in sites.txt  --
@echo --------------------------------------------
for /f %%X in (sites.txt) do msbuild build.xml /p:ProjectName="%%X" /v:n

This solution resides on in a directory on the same level as the rest of the websites from the root, which why the "..\$(ProjectName)" in the build script.

Great way of publishing a bunch of sites, and hope this helps someone.

太傻旳人生 2024-12-28 05:15:28

元素与自定义元数据结合使用,结果如下所示:

   <ItemGroup>
      <ProjectToPublish Include="WebApplication1\WebApplication1.csproj" >
                <OutputDir>OutputDir1</OutputDir>
      </ProjectToPublish>
      <ProjectToPublish Include="WebApplication2\WebApplication2.csproj" >
                <OutputDir>OutputDir2</OutputDir>
      </ProjectToPublish>
   </ItemGroup>

   <Target Name="Publish" Inputs="@(ProjectsToPublish)" Outputs="%(Identity).Dummy">
      <RemoveDir Directories="%(OutputDir)" ContinueOnError="true" />
      <MSBuild Projects="%(Identity)"
         Targets="ResolveReferences;_CopyWebApplication"
         Properties="WebProjectOutputDir=$(OutputDir);
         OutDir=%(OutputDir)\" />
   </Target>

Use an <ItemGroup /> element with custom metadata resulting in something like follows:

   <ItemGroup>
      <ProjectToPublish Include="WebApplication1\WebApplication1.csproj" >
                <OutputDir>OutputDir1</OutputDir>
      </ProjectToPublish>
      <ProjectToPublish Include="WebApplication2\WebApplication2.csproj" >
                <OutputDir>OutputDir2</OutputDir>
      </ProjectToPublish>
   </ItemGroup>

   <Target Name="Publish" Inputs="@(ProjectsToPublish)" Outputs="%(Identity).Dummy">
      <RemoveDir Directories="%(OutputDir)" ContinueOnError="true" />
      <MSBuild Projects="%(Identity)"
         Targets="ResolveReferences;_CopyWebApplication"
         Properties="WebProjectOutputDir=$(OutputDir);
         OutDir=%(OutputDir)\" />
   </Target>
谁的年少不轻狂 2024-12-28 05:15:28

所以我终于有时间再看一遍。

我创建了以下 MSBuild 脚本,该脚本位于与我拥有的所有网站处于同一级别的文件夹中。

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">


  <Target Name ="DeleteFiles">
    <Delete Files="..\$(ProjectName)\$(ProjectName)\obj\debug\$(ProjectName).dll"></Delete>
    <Delete Files="..\$(ProjectName)\$(ProjectName)\obj\release\$(ProjectName).dll"></Delete>
    <Delete Files="..\$(ProjectName)\$(ProjectName)\bin\$(ProjectName).dll"></Delete>
    <Delete Files="..\$(ProjectName)\$(ProjectName)\bin\$(ProjectName).pdb"></Delete>
  </Target>

  <Target Name="Compile" DependsOnTargets="DeleteFiles">
    <MSBuild Projects="..\$(ProjectName)\$(ProjectName)\$(ProjectName).csproj"
      Targets="Clean;Build"
      Properties="OutputPath=..\$(ProjectName)\bin"/>
  </Target>

  <Target Name="Deploy" DependsOnTargets="Compile">
    <MSBuild Projects="..\$(ProjectName)\$(ProjectName)\$(ProjectName).csproj"
        Targets="ResolveReferences;_CopyWebApplication"
        Properties="OutDir=C:\inetpub\wwwroot\$(ProjectName)\bin\;WebProjectOutputDir=C:\inetpub\wwwroot\$(ProjectName)" />
  </Target>


</Project>

并被这样调用:

msbuild build.xml /p:ProjectName="websitetopublish.com" /v:n

对于一个站点来说效果很好,但是我想要一个读取文本文件的与批处理相关的解决方案。对于该文本文件中的每个条目执行构建过程。

我可以轻松地为此编写一个 .Net 控制台应用程序,但有点过分了,我想知道如何使用批处理文件中的一些 for 循环机制来完成此任务。

So I finally had time to take a look at this again.

I created the following MSBuild script that resides in a folder at the same level of all the websites I have.

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">


  <Target Name ="DeleteFiles">
    <Delete Files="..\$(ProjectName)\$(ProjectName)\obj\debug\$(ProjectName).dll"></Delete>
    <Delete Files="..\$(ProjectName)\$(ProjectName)\obj\release\$(ProjectName).dll"></Delete>
    <Delete Files="..\$(ProjectName)\$(ProjectName)\bin\$(ProjectName).dll"></Delete>
    <Delete Files="..\$(ProjectName)\$(ProjectName)\bin\$(ProjectName).pdb"></Delete>
  </Target>

  <Target Name="Compile" DependsOnTargets="DeleteFiles">
    <MSBuild Projects="..\$(ProjectName)\$(ProjectName)\$(ProjectName).csproj"
      Targets="Clean;Build"
      Properties="OutputPath=..\$(ProjectName)\bin"/>
  </Target>

  <Target Name="Deploy" DependsOnTargets="Compile">
    <MSBuild Projects="..\$(ProjectName)\$(ProjectName)\$(ProjectName).csproj"
        Targets="ResolveReferences;_CopyWebApplication"
        Properties="OutDir=C:\inetpub\wwwroot\$(ProjectName)\bin\;WebProjectOutputDir=C:\inetpub\wwwroot\$(ProjectName)" />
  </Target>


</Project>

And is called like this:

msbuild build.xml /p:ProjectName="websitetopublish.com" /v:n

Works great for one site, however I'd like a batch-related solution that reads a text file. For each entry in that text file execute the build process.

I easily write a .Net console app to to this, but overkill, and I'd like to know how to accomplish this using some for looping mechanisms in batch files.

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