7

是否可以告诉 MSBuild 不要为某个程序集或所有程序集复制附属程序集?

我有一个 nuget 包,其中包含资源程序集,但我不想将它们包含在我的输出中。

谢谢。

4

2 回答 2

0

您可以有一个单独的文件夹用于部署,例如 \Build_Archive,其中也复制了输出 - 并在构建脚本中添加一些行以复制您的程序集,但不将卫星程序集复制到这些文件夹 - 这样,Build_Archive 总是只有文件您的部署所需的。

即,我当前的脚本复制到标记为 build# 的文件夹和 Current 文件夹 - 所以 Current 总是有最新的,并且我们维护先前构建的历史 - 例如:

C:\Build_Archive\AppName\Current
C:\Build_Archive\AppName\1.0.0.1
C:\Build_Archive\AppName\1.0.0.2

所以在你的构建脚本末尾有这样的东西(替换<values>你的东西。我们的脚本使用外部 DLL 来管理版本号等,所以不包括在这里):

 <!-- . . . -->
 <DropLocation>\\<serverName>\Build_Archive\${BuildDefinition}</DropLocation>
 <!-- . . . -->

 <!-- Version numbers major and build are replaced by outside calls not shown -->
 <PropertyGroup>
   <VersionMajor>1</VersionMajor>
   <VersionMinor>0</VersionMinor>
   <VersionService>0</VersionService>
   <VersionBuild>0</VersionBuild>
 </PropertyGroup>

 <Target Name="BuildNumberOverrideTarget">
 <!-- Create a custom build number, matching the assembly version -->
 <!-- . . . -->
 <!-- …  custom version code call – returns / sets VersionMajor and VersionBuild -->
  <PropertyGroup>
   <BuildNumber>$(BuildDefinitionName)_$(VersionMajor).$(VersionMinor).$(VersionService).$(VersionBuild)</BuildNumber>
  </PropertyGroup>
  <Message Text="Build number set to &quot;$(BuildNumber)&quot;" />
  <Message Text="$(SolutionRoot)"/>
 </Target>


 <Target Name="AfterCompile">
 <!-- Call Copy process after the build -->
  <CallTarget Targets="CleanUp"/>
  <CallTarget Targets="StageBuild"/>
  <CallTarget Targets="CopyFiles"/>
 </Target>

 <!-- Target : Clean Current Folder for next build -->
 <Target Name="CleanUp">
  <Message Text="**** Entering::CleanUp ****"/>
  <CreateItem Include="\\<server name>\Build_Archive\<appName>\Current\**\*.*">
   <Output ItemName="PreviousFiles" TaskParameter="Include" />
  </CreateItem>
  <Delete Files="@(PreviousFiles)" ContinueOnError="true" />
 </Target>

 <!-- Target:StageBuild -->
 <Target Name="StageBuild">
 <ItemGroup>
  <BldCurrent Include="\\<server name>\Build_Archive\<appName>\Current\"/>
 </ItemGroup>
 <Message Text="@(BldCurrent)"/>
 <Message Text="$(SolutionRoot)"/>
 <!— Here – replace next line with commands to copy only the files you want to deploy -->
  <Exec Command="xcopy /y /r /e $(SolutionRoot)\..\bin\*.* @(BldCurrent)"/>
 </Target>

 <!-- Target : Copy files from Current to BuildNum folder -->
 <Target Name="CopyFiles">
  <Exec Command="xcopy /y /r /e $(DropLocation)\Current\Debug\*.* $(DropLocation)\$(BuildNumber)\Debug\"/>

  <Exec Command="Del /Q $(DropLocation)\Current\Debug\*.config"/>
  <Exec Command="Del /Q $(DropLocation)\Current\Debug\*.dll"/>
  <Exec Command="Del /Q $(DropLocation)\Current\Debug\*.exe"/>
  <Exec Command="Del /Q $(DropLocation)\Current\Debug\*.application"/>
  <Exec Command="Del /Q $(DropLocation)\Current\Debug\*.pdb"/>
  <Exec Command="Del /Q $(DropLocation)\Current\Debug\*.txt"/>
  <Exec Command="Del /Q $(DropLocation)\Current\Debug\*.xml"/>
 </Target>
于 2015-01-22T21:08:54.380 回答
0

尝试使用以下参数调用 MSBuild:

/p:UseWPP_CopyWebApplication=True /p:PipelineDependsOnBuild=False

这将像 VisualStudio 一样应用 web.config 转换。此外,bin 文件夹输出也与 VisualStudio 发布中的相同。附属程序集不会直接复制到 bin 文件夹中,而是保留在其 bin 子文件夹中。

也可以看看:

于 2017-05-16T09:52:24.103 回答