代码之家  ›  专栏  ›  技术社区  ›  Maslow

如何重写从调用项目目标的生成脚本导入的项目目标?

  •  0
  • Maslow  · 技术社区  · 14 年前

    在项目文件中,我有以下内容

    <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />

    我无法改变。

    到目前为止我的尝试 <Properties>CustomAfterMicrosoftCommonTargets=D:\Projects\OverrideCopyWebApplication.targets</Properties>

    不工作。

    这是我正在使用的自定义.targets文件:

    <?xml version="1.0" encoding="utf-8" ?>
    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <ItemDefinitionGroup>
    <ProjectReference Condition="'$(OverrideCopyLocalProject)'=='true'">
      <Private>False</Private>
    </ProjectReference>
    <Reference Condition="'$(OverrideCopyLocal)'=='true'">
      <Private>False</Private>
    </Reference>
    </ItemDefinitionGroup>
    <Target Name="_CopyWebApplication" Condition="'$(OutDir)' != '$(OutputPath)'" >
    <!-- Log tasks -->
    <Message Text="Overridden Copying Web Application Project Files for $(MSBuildProjectName)" />
    
    <!-- Create the _PublishedWebsites\app\bin folder -->
    <MakeDir Directories="$(WebProjectOutputDir)\bin" />
    
    <!-- Copy build outputs to _PublishedWebsites\app\bin folder -->
    <Copy SourceFiles="@(IntermediateAssembly)" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" />
    <Copy SourceFiles="@(AddModules)" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" />
    <Copy SourceFiles="$(IntermediateOutputPath)$(_SGenDllName)" DestinationFolder="$(WebProjectOutputDir)\%(Content.SubFolder)%(Content.RecursiveDir)" SkipUnchangedFiles="true" Condition="'$(_SGenDllCreated)'=='true'" />
    <Copy SourceFiles="$(IntermediateOutputPath)$(TargetName).pdb" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" Condition="'$(_DebugSymbolsProduced)'=='true'" />
    <Copy SourceFiles="@(DocFileItem)" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" Condition="'$(_DocumentationFileProduced)'=='true'" />
    <Copy SourceFiles="@(IntermediateSatelliteAssembliesWithTargetPath)" DestinationFiles="@(IntermediateSatelliteAssembliesWithTargetPath->'$(WebProjectOutputDir)\bin\%(Culture)\$(TargetName).resources.dll')" SkipUnchangedFiles="true" />
    <Copy SourceFiles="@(ReferenceComWrappersToCopyLocal); @(ResolvedIsolatedComModules); @(_DeploymentLooseManifestFile); @(NativeReferenceFile)" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" />
    
    <!-- copy any referenced assemblies to _PublishedWebsites\app\bin folder -->
    <Copy SourceFiles="@(ReferenceCopyLocalPaths)" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" />
    <Message Text="Content=$(Content)" />
    <!-- Copy content files recursively to _PublishedWebsites\app\ folder -->
    <Copy SourceFiles="@(Content)" DestinationFolder="$(WebProjectOutputDir)\%(Content.RelativeDir)" />
    
    <!-- Copy items that have been marked to be copied to the bin folder -->
    <Copy SourceFiles="@(_SourceItemsToCopyToOutputDirectory)" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" />
    <Copy SourceFiles="@(_SourceItemsToCopyToOutputDirectoryAlways)" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="false" />
    </Target>
    </Project>
    

    我直接从我试图构建的项目指向的文件中复制了现有目标,并添加/更改了一些消息以查看它是否工作。它不会调用自定义重写。

    如何在构建脚本的项目文件中重写此导入?无法更改项目文件。我使用的msbuild 4.0设置为工具版本3.5,但我希望它也能与msbuild3.5一起使用。

    1 回复  |  直到 14 年前
        1
  •  0
  •   Community CDub    8 年前

    好吧,我更明白你想做什么。不幸的是,我不知道你是否可以覆盖这些目标。是否尝试修改CopyWebApplication以检查在生成结束时是否正确调用了目标?

    不过,此线程可能会帮助您: Can you prevent MSBuild.exe from running Build Events?