我们有在 VS2010 之外创建的内容(文件/文件夹)。使用项目的“BeforeBuild”,我可以将临时目录中的文件导入到项目的相同目录结构中。导入后,我们如何告诉 VS2010 IDE 将 Build Action 识别为“内容”?在 VS2010 IDE 中,宏“包含在项目中”会为您执行此操作。它与指定文件的元数据有什么关系吗?这是我到目前为止...
<Target Name="BeforeBuild" Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' " DependsOnTargets="ImportProperties;CustomImportsTarget" />
<Target Name="ImportProperties">
<PropertyGroup>
<ImportSrcPath>$(temp)\$(MSBuildProjectName)\Imports</ImportSrcPath>
<!-- File to save project references to -->
<ImportLogFile>$(ImportSrcPath)\ImportResults.txt</ImportLogFile>
</PropertyGroup>
</Target>
<Target Name="ImportLogger">
<Delete Files="$(ImportLogFile)" />
<WriteLinesToFile File="$(ImportLogFile)" Lines="Import Results%09============" />
</Target>
<Target Name="CustomImportsTarget" Condition="Exists('$(ImportSrcPath)')" DependsOnTargets="ImportLogger">
<!--
==============================================================
Allows for dynamically created content (files/folders) to be imported from our temp directory to our project's same
directory structure as "Compile Include content"
i.e. move %temp%\scripts\1.1.0\sample.js to <project>\scripts\1.1.0\sample.js
==============================================================
-->
<Message Text="==============================================================%0aCustomImportsTarget Begin%0a==============================================================" />
<!-- Create an Item list that contains the files to import. $(ImportSrcPath) is the property that contains the location where
import source files are placed. -->
<CreateItem Include="$(ImportSrcPath)\**\*" Exclude="$(ImportLogFile)">
<Output TaskParameter="Include" ItemName="Files2Import" />
</CreateItem>
<!-- For testing purposes, Copy the files into our project. TODO:Should be a Move operation so project file modified dates are not constantly changing. -->
<Copy SkipUnchangedFiles="false" SourceFiles="@(Files2Import)" DestinationFolder="$(MSBuildProjectDirectory)\%(Files2Import.RecursiveDir)">
<Output TaskParameter="CopiedFiles" ItemName="Changed" />
</Copy>
<!-- Imported files are now located in our project folders,
How do we assign properties to the files in @(Changed) so VS2010 IDE recognizes Build Action as "Content"???
In VS2010 IDE, the macro "Include in Project" does this for you. Does it have anything to do with specifying a file's MetaData???
-->
<!-- Now send these values to the logger -->
<Message Text="Changed:@(Changed->'%(Filename)%(Extension)')" Importance="high" />
<Message Text="Script:@(Files2Import->'%(Filename)%(Extension)')" Importance="high" />
<!--<Message Text="MSBuildProjectDirectory:$(MSBuildProjectDirectory)" Importance="high" />-->
<Message Text="==============================================================%0aCustomImportsTarget End%0a==============================================================" />
</Target>