c# - 具有许多 Web 项目输出到同一目录的 MSBuild 解决方案

标签 c# asp.net asp.net-mvc-3 msbuild

我想构建许多 Web 项目并将它们输出到目录,例如 ./output/Project1 ./output/Project2 等。这些文件夹中的每一个基本上都包含输出到 _PublishedWebsites 的内容。我试过这个:

msbuild support.sln /p:configuration=Release;DeployOnBuild=true;DeployTarget=Package;_PackageTempDir=c:/ws/code/supportsite/output/ /t:package

但它似乎用每个构建的项目覆盖了输出目录的内容。

最佳答案

为什么不制作目标文件。

XCopyWebDeploy.targets

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>

        <XCopyDeployWebPackage Condition="  '$(XCopyDeployWebPackage)' == '' ">false</XCopyDeployWebPackage>
    </PropertyGroup>

    <ItemGroup>
        <ProjectFileItem Include="$(ProjectPath)"/>
    </ItemGroup>

    <PropertyGroup>
        <!-- Make the build depend on web deploy packages -->
        <BuildDependsOn Condition="$(XCopyDeployWebPackage) == 'true'">
            $(BuildDependsOn);
            Package;
            XCopyDeployWebPackage;
        </BuildDependsOn>
    </PropertyGroup>

    <Target Name="XCopyDeployWebPackage">
        <CreateItem Include="$(ProjectDir)obj\$(Configuration)\Package\PackageTmp\**\*.*">
            <Output ItemName="XCopyWebDeployPackageOutputFiles" TaskParameter="Include"/>
        </CreateItem>
        <CreateProperty Value="c:\ws\code\supportsite\output\%(ProjectFileItem.Filename)">
            <Output PropertyName="XCopyWebDeployOutput" TaskParameter="Value"/>
        </CreateProperty>
        <Copy 
            SourceFiles="@(XCopyWebDeployPackageOutputFiles)"
            DestinationFiles="@(XCopyWebDeployPackageOutputFiles->'$(XCopyWebDeployOutput)\%(RecursiveDir)%(Filename)%(Extension)')"/>
    </Target>
</Project>

并导入 web 项目文件。

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
    <PropertyGroup>
        <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
        <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
        <ProductVersion>
        </ProductVersion>
        <SchemaVersion>2.0</SchemaVersion>
        <ProjectGuid>{BF6B6392-1398-42D3-AA90-ED87D02D351A}</ProjectGuid>
        <ProjectTypeGuids>{E3E379DF-F4C6-4180-9B81-6769533ABE47};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
        <OutputType>Library</OutputType>
        <AppDesignerFolder>Properties</AppDesignerFolder>
        <RootNamespace>MvcApplication1</RootNamespace>
        <AssemblyName>MvcApplication1</AssemblyName>
        <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
        <MvcBuildViews>false</MvcBuildViews>
        <UseIISExpress>true</UseIISExpress>
        <IISExpressSSLPort />
        <IISExpressAnonymousAuthentication />
        <IISExpressWindowsAuthentication />
        <IISExpressUseClassicPipelineMode />
        <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
        <RestorePackages>true</RestorePackages>
        <!--!!!-->
        <XCopyDeployWebPackage>true</XCopyDeployWebPackage>
        <!--!!!-->
    </PropertyGroup>

    <!-- Some lines omitted -->

    <Import Project="$(SolutionDir)\.nuget\nuget.targets" />

    <!--!!!-->
    <Import Project="$(SolutionDir)\XCopyWebDeploy.targets" />
    <!--!!!-->

    <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.
    <Target Name="BeforeBuild">
    </Target>
    <Target Name="AfterBuild">
    </Target> -->
</Project> 

关于c# - 具有许多 Web 项目输出到同一目录的 MSBuild 解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10504794/

相关文章:

c# - Xamarin.Forms、XAML - 如何显示带颜色叠加的图像

asp.net - 用户 ASP.NET 运行于

asp.net - Asp 将查询放入数组并在不刷新页面的情况下通过它

asp.net-mvc-3 - w3wp.exe 有内存限制吗?

c# - 还有另一种方法可以检查用户所在的 .net 角色吗?

c# - 从本地控制台应用程序的 C++/CLI DLL 调用 C# 库时,无法授予最低权限请求

c# - 使用服务引用时无法将 IAsyncResult 转换为 AsyncResult

c# - TimeSpan.ToString ("hh:mm") 错误

asp.net - 下拉列表垂直居中对齐

c# - 使用 Entity Framework 的模型上的显示名称