gpt4 book ai didi

msbuild-4.0 - 当您导入另一个 msbuild 文件时,评估的顺序是什么?

转载 作者:行者123 更新时间:2023-12-04 00:50:49 26 4
gpt4 key购买 nike

我有一个共享属性文件 shared.properties.proj

<Project  xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SharedAssemblySearch>$(MSBuildProjectDirectory)\..\Shared Assemblies</SharedAssemblySearch>
<ParentDir>..</ParentDir>
<SharedAssemblySearch Condition="!Exists('$(SharedAssemblySearch)')">$(ParentDir)\$(SharedAssemblySearch)</SharedAssemblySearch>
<SharedAssemblySearch Condition="!Exists('$(SharedAssemblySearch)')">$(ParentDir)\$(SharedAssemblySearch)</SharedAssemblySearch>
<SharedAssemblySearch Condition="!Exists('$(SharedAssemblySearch)')">$(ParentDir)\$(SharedAssemblySearch)</SharedAssemblySearch>
<SharedAssemblySearch Condition="!Exists('$(SharedAssemblySearch)')">$(ParentDir)\$(SharedAssemblySearch)</SharedAssemblySearch>
<SharedAssemblySearch Condition="!Exists('$(SharedAssemblySearch)')">$(ParentDir)\$(SharedAssemblySearch)</SharedAssemblySearch>
<SharedAssemblySearch Condition="!Exists('$(SharedAssemblySearch)')">$(ParentDir)\$(SharedAssemblySearch)</SharedAssemblySearch>
<SharedAssemblyPath Condition="Exists('$(SharedAssemblySearch)')">$(SharedAssemblySearch)</SharedAssemblyPath>
<SharedAssemblySearch Condition="!Exists('$(SharedAssemblySearch)')">..\SharedAssemblies</SharedAssemblySearch>
<SharedAssemblySearch Condition="!Exists('$(SharedAssemblySearch)')">$(ParentDir)\$(SharedAssemblySearch)</SharedAssemblySearch>
<SharedAssemblySearch Condition="!Exists('$(SharedAssemblySearch)')">$(ParentDir)\$(SharedAssemblySearch)</SharedAssemblySearch>
<SharedAssemblySearch Condition="!Exists('$(SharedAssemblySearch)')">$(ParentDir)\$(SharedAssemblySearch)</SharedAssemblySearch>
<SharedAssemblySearch Condition="!Exists('$(SharedAssemblySearch)')">$(ParentDir)\$(SharedAssemblySearch)</SharedAssemblySearch>
<SharedAssemblyPath Condition="Exists('$(SharedAssemblySearch)')">$(SharedAssemblySearch)</SharedAssemblyPath>
</PropertyGroup>
</project>

我正在搜索包含名为 Shared Assemblies 的目录的任何级别的父目录.或者 SharedAssemblies
我想将此代码放在 sln 的中心位置,以便所有项目都可以导入它。 sln 中的项目并不都处于同一层次结构级别。

sample .csproj
    <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Shared.Properties.proj))\Shared.Properties.proj"
Condition=" '$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Shared.Properties.proj))' != '' "/>
<ItemGroup>
<Reference Include="EntityFramework">
<HintPath>$(SharedAssemblyPath)\NuGet\EntityFramework.4.3.0\lib\net40\EntityFramework.dll</HintPath>
</Reference>
</ItemGroup>
<Target Name="CheckReferencePaths" BeforeTargets="ResolveAssemblyReferences">
<Message Importance="high" Text="Doing CheckReferencePaths" />
<ItemGroup>
<SharedAssemblyPathItem Include="$(SharedAssemblyPath)" />
</ItemGroup>
<Warning Condition="!Exists('@(SharedAssemblyPathItem)')" Text="SharedAssemblyPath not found at '@(SharedAssemblyPathItem)'" />
<Warning Condition="!Exists('@(SharedAssemblyPathItem)')" Text="SharedAssemblyPath not found at '@(SharedAssemblyPathItem->'%(FullPath)')'" />
<Message Condition="!Exists('%(Reference.HintPath)')" Text="FullPath=%(Reference.HintPath)" Importance="high" />



我在主项目中进行了这个工作,而没有将属性组推送到我导入的卫星文件中,但现在想让它可以在可以共享引用的其他项目之间重复使用。
BeforeTargets目标在不工作的新尝试上显示了这一点:

CheckReferencePaths: Doing CheckReferencePaths D:\projects\Team\Project\Adapters\DbAdapter\dbadapter.csproj(103,5): warning : SharedAssemblyPath not found at '' D:\projects\Team\Project\Adapters\DbAdapter\dbadapter.csproj(104,5): warning : SharedAssemblyPath not found at ''
FullPath=\NuGet\EntityFramework.4.3.0\lib\net40\EntityFramework.dll
FullPath=



在评估项目组的提示路径之前,如何获取导入共享的项目文件以评估导入的项目的属性。或者评估顺序是否正确,但我的构造中的其他内容不正确?

最佳答案

你的问题让我找到了这个有值(value)的 info on MSDN .我把它贴在这里是为了保留答案 self-contained .

评估顺序

当 MSBuild 达到 进口 元素,导入的项目有效地插入到导入项目中 的位置。进口 元素。因此,的位置进口 元素可以影响属性和项目的值。了解导入项目设置的属性和项目以及导入项目使用的属性和项目很重要。

项目构建时,首先评估所有属性,然后是项目。例如,以下 XML 定义了导入的项目文件 MyCommon.targets:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Name>MyCommon</Name>
</PropertyGroup>

<Target Name="Go">
<Message Text="Name='$(Name)'"/>
</Target>
</Project>

以下 XML 定义了 MyApp.proj,它导入 MyCommon.targets:
<Project
DefaultTargets="Go"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Name>MyApp</Name>
</PropertyGroup>
<Import Project="MyCommon.targets"/>
</Project>

项目构建时,将显示以下消息:

名称="MyCommon"

因为项目是在 MyApp.proj 中定义 Name 属性之后导入的,所以 MyCommon.targets 中 Name 的定义会覆盖 MyApp.proj 中的定义。如果在定义属性 Name 之前导入项目,则构建将显示以下消息:

名称="我的应用程序"

导入项目时使用以下方法
  • 在项目文件中定义所有使用的属性和项目
    作为导入项目中的属性和项目的参数。
  • 导入项目。
  • 在项目文件中定义所有必须
    覆盖导入的属性和项目的默认定义
    项目。

  • 例子

    下面的代码示例显示了第二个代码示例导入的 MyCommon.targets 文件。 .targets 文件评估来自导入项目的属性以配置构建。
    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
    <Flavor Condition="'$(Flavor)'==''">DEBUG</Flavor>
    <Optimize Condition="'$(Flavor)'=='RETAIL'">yes</Optimize>
    <appname>$(MSBuildProjectName)</appname>
    <PropertyGroup>
    <Target Name="Build">
    <Csc Sources="hello.cs"
    Optimize="$(Optimize)"
    OutputAssembly="$(appname).exe"/>
    </Target>
    </Project>

    下面的代码示例导入 MyCommon.targets 文件。
    <Project DefaultTargets="Build"
    xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
    <Flavor>RETAIL</Flavor>
    </PropertyGroup>
    <Import Project="MyCommon.targets"/>
    </Project>

    关于msbuild-4.0 - 当您导入另一个 msbuild 文件时,评估的顺序是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9536913/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com