发布到Azure之前的清理/重建解决方案

时间:2014-08-12 12:26:17

标签: asp.net asp.net-mvc visual-studio azure msbuild

我有一个解决方案,包括与ASP.Net MVC应用程序松散耦合的项目。我已将所有项目的输出设置为“MvcProject \ bin”文件夹。因此,在我能够运行我的Web应用程序之前,我需要清理/重建解决方案。问题是,当我将其发布到Azure或本地系统时,它将不包括所有项目dll(及其相关的dll,它将仅包括MvcProject及其依赖的dll)。是否有任何方法可以告诉VS(或msbuild)清理/重建解决方案并包含所有相关的项目dll,其输出设置为'MvcProject \ bin'

1 个答案:

答案 0 :(得分:0)

这就是我所做的。首先编辑我所有的类库项目csproj文件OutPath to,

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> 
    ..................................
    <OutputPath>bin\Debug\</OutputPath>
    ..................................


<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> 
    ..................................
    <OutputPath>bin\Release\</OutputPath>
    ..................................

接下来将此添加到我的MVC应用程序csproj文件底部(</Project>之前),

  <Target Name="AfterBuild">
    <ItemGroup>
      <_CustomFiles Include="..\Project1\bin\$(Configuration)\**\*;..\Project2\bin\$(Configuration)\**\*" />
        ................................................................
    </ItemGroup>
    <Copy SourceFiles="@(_CustomFiles)" DestinationFiles="@(_CustomFiles->'bin\%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
  </Target>

最后将此添加到我的Azure.pubxml(您可以在Properties/PublishProfiles)文件底部(</Project>之前)中找到它,

  <Target Name="CustomCollectFiles">
    <ItemGroup>
         <_CustomFiles Include="..\Project1\bin\$(Configuration)\**\*;..\Project2\bin\$(Configuration)\**\*" />
            ................................................................
      <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
        <DestinationRelativePath>bin\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
      </FilesForPackagingFromProject>
    </ItemGroup>
  </Target>
  <PropertyGroup>
    <CopyAllFilesToSingleFolderForPackageDependsOn>
      CustomCollectFiles;
      $(CopyAllFilesToSingleFolderForPackageDependsOn);
    </CopyAllFilesToSingleFolderForPackageDependsOn>
    <CopyAllFilesToSingleFolderForMsdeployDependsOn>
      CustomCollectFiles;
      $(CopyAllFilesToSingleFolderForPackageDependsOn);
    </CopyAllFilesToSingleFolderForMsdeployDependsOn>
  </PropertyGroup>