【问题标题】:How do you override a project target import from a build script that calls it?如何从调用它的构建脚本中覆盖项目目标导入?
【发布时间】:2010-09-22 12:54:22
【问题描述】:

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

<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>

我直接从我正在尝试构建的项目所指向的文件中复制了现有的目标,并且只是添加/更改了一些消息以查看它是否正常工作。它没有调用自定义覆盖。

如何在构建脚本的项目文件中覆盖此导入?不能更改项目文件。我正在使用设置为工具版本 3.5 的 MsBuild 4.0,但我希望它也能够与 MsBuild3.5 一起使用。

【问题讨论】:

  • 我不明白:您将引用的物业代码放在哪里?你如何开始构建?你对原始项目文件做了什么?
  • 属性元素位于调用项目文件的构建脚本的 msbuild 任务中。我通过 cc.net 开始构建。它调用我的自定义构建脚本来获取所有项目文件,并调用其中包含此属性元素的 msbuildtask。

标签: msbuild


【解决方案1】:

好的,我更了解您想要做什么。不幸的是,我不知道您是否可以覆盖这些目标。您是否尝试修改 _CopyWebApplication 以在构建结束时检查目标是否正确调用?

不过,这个帖子可能会对您有所帮助:Can you prevent MSBuild.exe from running Build Events?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-04
    • 1970-01-01
    • 1970-01-01
    • 2021-02-14
    • 2020-06-17
    • 1970-01-01
    • 2015-06-05
    • 2015-09-25
    相关资源
    最近更新 更多