小编R. *_*yev的帖子

MSBuild。在构建之前创建 EmbeddedResource

我想在编译主单元之前在程序集中嵌入本地引用。但是写的目标不起作用。

  <Target Name="EmbedLocal" BeforeTargets="CoreCompile">
    <Message Text="Run EmbedLocal for $(MSBuildProjectFullPath)..." Importance="high"/>    
    <ItemGroup>
      <EmbeddedResource Include="@( ReferencePath->WithMetadataValue( 'CopyLocal', 'true' )->Metadata( 'FullPath' ) )"/>
    </ItemGroup>
    <Message Text="Embed local references complete for $(OutputPath)$(TargetFileName)." Importance="high" />
  </Target>
Run Code Online (Sandbox Code Playgroud)

@(EmbeddedResource) 此时包含有效的路径列表。

更新:
现在我的导入文件包含:

<Project ToolsVersion="$(MSBuildToolsVersion)" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <EmbedLocalReferences Condition=" '$(EmbedLocalReferences)' == '' ">True</EmbedLocalReferences>
  </PropertyGroup>

  <Target Name="EmbedLocal" BeforeTargets="ResolveReferences" Condition=" '$(EmbedLocalReferences)' == 'True' ">
    <Message Text="Run EmbedLocal for $(MSBuildProjectFullPath)..." Importance="high"/>
    <ItemGroup>
      <EmbeddedResource Include="@(ReferenceCopyLocalPaths->WithMetadataValue( 'Extension', '.dll' )->Metadata( 'FullPath' ))">
        <LogicalName>%(ReferenceCopyLocalPaths.Filename)%(ReferenceCopyLocalPaths.Extension)</LogicalName>
      </EmbeddedResource>
    </ItemGroup>   
    <Message Text="Embed local references complete for $(OutputPath)$(TargetFileName)." Importance="high" /> …
Run Code Online (Sandbox Code Playgroud)

c# msbuild csproj visual-studio

3
推荐指数
1
解决办法
3245
查看次数

标签 统计

c# ×1

csproj ×1

msbuild ×1

visual-studio ×1