Asp.net-Mvc-3

vs12 不再支持 CopyAllFilesToSingleFolderForPackageDependsOn

  • June 23, 2015

我正在為網站使用 Visual Studio 2012 包功能,並且我有一個自定義目標,用於在壓縮文件夾之前將一些子文件夾收集到包目標中。這在 vs10 中執行良好,但使用新的打包程序 vs12 不再關心這些配置中的任何一個,並且它們沒有被正確遷移以做類似的事情,所以我的包最終會有這些文件?

這是它曾經在 vs10 中的樣子:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
   <DebugType>pdbonly</DebugType>
   <Optimize>true</Optimize>
   <OutputPath>bin\</OutputPath>
   <DefineConstants>TRACE</DefineConstants>
   <ErrorReport>prompt</ErrorReport>
   <WarningLevel>4</WarningLevel>
   <!-- Begin copy Contracts &Provider directories -->
   <CopyAllFilesToSingleFolderForPackageDependsOn>
     CustomCollectFiles;
     $(CopyAllFilesToSingleFolderForPackageDependsOn);
   </CopyAllFilesToSingleFolderForPackageDependsOn>
   <DesktopBuildPackageLocation>..\Package\Release\projectname.zip</DesktopBuildPackageLocation>
   <DeployIisAppPath>projectname</DeployIisAppPath>
   <!-- End copy Contracts &Provider directories -->
 </PropertyGroup>

 <Target Name="CustomCollectFiles">
   <ItemGroup>
     <_CustomFiles Include="$(OutputPath)\Contracts\**\*" />
     <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
       <DestinationRelativePath>bin\Contracts\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
     </FilesForPackagingFromProject>
   </ItemGroup>
   <ItemGroup>
     <_CustomFiles Include="$(OutputPath)\Providers\**\*" />
     <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
       <DestinationRelativePath>bin\Providers\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
     </FilesForPackagingFromProject>
   </ItemGroup>

這在新項目中完全被忽略了。做類似事情的好方法是什麼?

找到了解決方案,只需重命名CopyAllFilesToSingleFolderForPackageDependsOnCopyAllFilesToSingleFolderForMsdeployDependsOn,文件應該包含在部署包中。

順便說一句,這仍然不是最好的解決方案,因為您需要同時維護兩者以支持 vs12 和 vs 10

另一種方法也有效並且需要較少的維護..

 <Target Name="CustomFolderDeploy" AfterTargets="CopyAllFilesToSingleFolderForPackage" BeforeTargets="MSDeployPublish">
   <PropertyGroup>
     <CustomFolder>$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\..\..\..\Lib\CustomFolder'))</CustomFolder>
   </PropertyGroup>
   <CreateItem Include="$(CustomFolder)\*.*">
     <Output TaskParameter="Include" ItemName="CustomFiles" />
   </CreateItem>
   <Copy SourceFiles="@(CustomFiles)" DestinationFolder="$(MSBuildProjectDirectory)\obj\$(Configuration)\Package\PackageTmp\bin" SkipUnchangedFiles="True" ContinueOnError="False" />
 </Target>

引用自:https://stackoverflow.com/questions/12235449