msbuildProjectDirectory无法为msbuild.extensionpack解决



我正在从事ASP.NET 4 WebAPI项目,并且包括wpp.targets文件。我需要使用msbuild.extensionpack.xml.xmlfile来替换我的一个配置xml文件中的值。

问题是我不想在所有机器上安装msbuild.extensionpack,因此我将其包装在项目中。在我的本地构建中,通往msbuild.extensionpack.dll的路径正确解决。不过,在我的构建计算机上,我一直遇到此错误:The "MSBuild.ExtensionPack.Xml.XmlFile" task could not be loaded from the assembly C:Program Files (x86)MSBuildExtensionPack4.0MSBuild.ExtensionPack.dll.

它似乎正在解决软件包的默认安装位置。

这是我的wpp.targets文件中的内容:

<?xml version="1.0" encoding="utf-8"?>

<!-- Sets the assembly which will run the transformation on Web.config (Should be installed on Dev machines) -->
<UsingTask TaskName="TransformXml"
           AssemblyFile="$(MSBuildExtensionsPath)MicrosoftVisualStudiov11.0WebMicrosoft.Web.Publishing.Tasks.dll"/>
<!-- Get the path to the MSBuild.Extension.Pack -->
<PropertyGroup>
    <TPath>$(MSBuildProjectDirectory)..packagesMSBuild.Extension.Pack.1.3.0toolsnet40MSBuild.ExtensionPack.tasks</TPath>
    <TPath Condition="Exists('$(MSBuildProjectDirectory)..packagesMSBuild.Extension.Pack.1.3.0toolsnet40MSBuild.ExtensionPack.tasks')">$(MSBuildProjectDirectory)..packagesMSBuild.Extension.Pack.1.3.0toolsnet40MSBuild.ExtensionPack.tasks</TPath>
</PropertyGroup>
<!--Import the MSBuild.Extension.Pack package -->
<Import Project="$(TPath)"/>
<!-- Make sure web.config and transformation files exist -->
<Target Name="ConfigurationTransform" BeforeTargets="BeforeBuild" Condition="Exists('Web.config')" />
<Target Name="ConfigurationTransform" BeforeTargets="BeforeBuild" Condition="Exists('Web.$(Configuration).config')" />
<!-- Make sure web.config will be there even for package/publish -->
<Target Name="CopyWebConfig" BeforeTargets="Build;Rebuild">
    <Copy SourceFiles="Web.Base.config"
          DestinationFiles="Web.config"
          OverwriteReadOnlyFiles="true"
          SkipUnchangedFiles="false" />
</Target>
<!-- Run Web.Config transformation on a build as well (not just a publish) -->
<Target Name="CustomTransformWebConfigOnBuild" AfterTargets="CopyWebConfig" >
    <Message Text="Transforming: Web.$(Configuration).config" Importance="high" />
    <TransformXml Source="Web.Base.config"
                  Transform="Web.$(Configuration).config"
                  Destination="Web.config" />
</Target>
<!-- Update Web.Config's config attribute -->
<Target Name="UpdateConfigAttribute" AfterTargets="CustomTransformWebConfigOnBuild" Condition="$(Configuration) != 'Release'">
    <Message Text="Transforming: Web.config" Importance="high" />       
    <MSBuild.ExtensionPack.Xml.XmlFile TaskAction="UpdateAttribute"
                                       File="Web.config"
                                       XPath="/configuration/appSettings/add[@key='config_url']"
                                       Key="value"
                                       Value="www.randomurl.com"/>
</Target>

当您有超过1个辅助位置的辅助位置时...我喜欢像下面的样式一样做。

类似的东西(显然,您必须将真实位置放在" PossiblelocationOne"one_answers" Possiblelocation"中)。

<PropertyGroup>
    <MyFoundMSBuildExtensionPackLocation Condition="Exists('..PossibleLocationOneMSBuild.ExtensionPack.dll')">..PossibleLocationOneMSBuild.ExtensionPack.dll</MyFoundMSBuildExtensionPackLocation>
    <MyFoundMSBuildExtensionPackLocation Condition="Exists('..PossibleLocationTwoMSBuild.ExtensionPack.dll')">..PossibleLocationTwoMSBuild.ExtensionPack.dll</MyFoundMSBuildExtensionPackLocation>
    <!--Now check to see if either of the two above resolved , if not , add something to the path so you can at least -->
    <MyFoundMSBuildExtensionPackLocation Condition="'$(MyFoundMSBuildExtensionPackLocation)'==''">DID_NOT_FIND_A_PATH_FOR_MSBUILDEXENSIONPACKMSBuild.ExtensionPack.dll</MyFoundMSBuildExtensionPackLocation>
</PropertyGroup>
<UsingTask AssemblyFile="$(MyFoundMSBuildExtensionPackLocation)" TaskName="TransformXml"/>

为可能位置添加所有选项。

然后使用" usedtask"。

" usingTask"是~~ ~~ ~~ ~~ ~~ y myfoundmsbuildextensionpacklocation(propertyGroup).......因此,$(myfoundmsbuildextensionpacklocation)在称为userTask之前就解决了。

相关内容

最新更新