我們擁有在VS2010之外創建的內容(文件/文件夾)。使用該項目的「BeforeBuild」,我可以將文件從我們的臨時目錄導入到我們項目的相同目錄結構中。一旦導入,我們如何告訴VS2010 IDE將Build Action識別爲「內容」?在VS2010 IDE中,宏「包含在項目中」爲您做到了這一點。它與指定文件的MetaData有什麼關係?這是我到目前爲止......如何使用構建操作「內容」將文件複製到項目中
<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>
我猜測可以通過使用T4模板來讀取/寫入動態生成的文件。 – Smartkid