Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
232 lines (201 sloc) 11.2 KB
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2014 Clarius Consulting SA
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="Clarius.VisualStudio.props" Condition="'$(ClariusVisualStudioPropsImported)' != 'true'" />
<!-- VsSDK.Common.targets is imported automatically by the VsSDK.targets -->
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets"
Condition="'$(OverrideVsSDK)' != 'false' And '$(DetokenizeVsixManifestFileDependsOn)' == '' And '$(VSToolsPath)' != '' And Exists('$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets')" />
<PropertyGroup>
<ClariusVisualStudioTargetsImported>true</ClariusVisualStudioTargetsImported>
</PropertyGroup>
<UsingTask TaskName="SetVsSDKEnv" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<VsSDKToolsPath Required="true" />
</ParameterGroup>
<Task>
<Code Type="Fragment" Language="cs">
System.Environment.SetEnvironmentVariable("VsSDKToolsPath", System.IO.Path.GetFullPath(VsSDKToolsPath),EnvironmentVariableTarget.Process);
</Code>
</Task>
</UsingTask>
<Target Name="SetVsSDKEnv" Condition="'$(OverrideVsSDK)' != 'false'" BeforeTargets="GeneratePkgDef;VSCTCompile">
<SetVsSDKEnv VsSDKToolsPath="$(VsSDKToolsPath)" />
</Target>
<Target Name="ReportVsSDKVersion" AfterTargets="Build">
<ReportVsSDK />
</Target>
<UsingTask TaskName="ReportVsSDK" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<Task>
<Using Namespace="Microsoft.Build.Framework" />
<Using Namespace="System.Reflection" />
<Code Type="Fragment" Language="cs">
<![CDATA[
var tasks = AppDomain.CurrentDomain.GetAssemblies ().FirstOrDefault (asm => asm.GetName ().Name == "Microsoft.VsSDK.Build.Tasks");
if (tasks != null)
{
Log.LogMessage(MessageImportance.High, "VSSDK: Microsoft.VsSDK.Build.Tasks, Version=" +
((AssemblyFileVersionAttribute)tasks.GetCustomAttribute(typeof(AssemblyFileVersionAttribute))).Version);
}
]]>
</Code>
</Task>
</UsingTask>
<PropertyGroup>
<!-- This makes it easy to change it to be $(TargetPath) instead -->
<SmartTemplateIntermediateOutputPath Condition="'$(SmartTemplateIntermediateOutputPath)' == ''">$(IntermediateOutputPath)</SmartTemplateIntermediateOutputPath>
<SmartTemplateIntermediateOutputFullPath>$([MSBuild]::Escape($([System.IO.Path]::GetFullPath('$([System.IO.Path]::Combine('$(MSBuildProjectDirectory)', '$(SmartTemplateIntermediateOutputPath)'))'))))</SmartTemplateIntermediateOutputFullPath>
<ShouldProcessSmartTemplates Condition="$([System.IO.Path]::GetExtension('$(MSBuildProjectFile)')) == '.tmp_proj'">false</ShouldProcessSmartTemplates>
<!-- Before compilation is done, we add our content files from smart templates -->
<PrepareForBuildDependsOn Condition="'$(ShouldProcessSmartTemplates)' != 'false'">
$(PrepareForBuildDependsOn);
FindSmartTemplateCandidates;
IncludeSmartTemplateFiles;
IncludeSmartTemplateIncludes
</PrepareForBuildDependsOn>
<!-- Before extension is deployed or VSIX built, we zip templates -->
<AssignTargetPathsDependsOn Condition="'$(ShouldProcessSmartTemplates)' != 'false'">
CopyOutOfDateSmartTemplateContent;
ZipSmartTemplateContent;
AddSmartTemplateZip;
$(AssignTargetPathsDependsOn)
</AssignTargetPathsDependsOn>
</PropertyGroup>
<!--
=======================================================================================================
Include all files including the .vstemplate
=======================================================================================================
-->
<Target Name="FindSmartTemplateCandidates">
<CreateItem Include="@(None)" Condition="'%(None.Extension)' == '.vstemplate'" PreserveExistingMetadata="true">
<Output TaskParameter="Include" ItemName="SmartVSTemplate" />
</CreateItem>
</Target>
<!--
=======================================================================================================
Include all files including the .vstemplate
=======================================================================================================
-->
<Target Name="IncludeSmartTemplateFiles" Condition="'@(SmartVSTemplate)' != ''">
<!-- Causes the wildcards to be resolved to generate one item per file -->
<CreateItem Include="%(SmartVSTemplate.RelativeDir)**\*.*">
<Output TaskParameter="Include" ItemName="_SmartTemplateRelativeFile" />
</CreateItem>
<!-- Leverage built-in task to assign TargetPath metadata -->
<AssignTargetPath Files="@(_SmartTemplateRelativeFile)" RootFolder="$(MSBuildProjectDirectory)">
<Output TaskParameter="AssignedFiles" ItemName="SmartTemplateContentWithTargetPath" />
</AssignTargetPath>
<!-- Add the smart template itself too, in case we need to process it later -->
<AssignTargetPath Files="@(SmartVSTemplate)" RootFolder="$(MSBuildProjectDirectory)">
<Output TaskParameter="AssignedFiles" ItemName="SmartTemplateWithTargetPath" />
</AssignTargetPath>
</Target>
<!--
=======================================================================================================
Include files added via semicolon-delimited <Include> metadata
=======================================================================================================
-->
<Target Name="IncludeSmartTemplateIncludes"
Inputs="@(SmartVSTemplate)"
Outputs="@(SmartVSTemplate -> %(Identity)-BATCH)"
Condition="'@(SmartVSTemplate)' != ''">
<!-- Splits by semicolon the Includes metadata of the template and generates one item for each
note that we're already batching the entire targets so that the SplitTemplateIncludes always
receives a single template file to perform the split on -->
<SplitTemplateIncludes Template="@(SmartVSTemplate)" Condition="'%(SmartVSTemplate.Include)' != ''">
<Output ItemName="_SmartTemplateInclude" TaskParameter="Includes" />
<Output ItemName="_SmartTemplateExclude" TaskParameter="Excludes" />
</SplitTemplateIncludes>
<!-- Causes the wildcards to be resolved to generate one item per file -->
<CreateItem Include="@(_SmartTemplateInclude)" PreserveExistingMetadata="true">
<Output TaskParameter="Include" ItemName="_SmartIncludedFileSource" />
</CreateItem>
<CreateItem Include="@(_SmartTemplateExclude)" PreserveExistingMetadata="true">
<Output TaskParameter="Include" ItemName="_SmartExcludedFileSource" />
</CreateItem>
<!-- Remove the excluded files from the source -->
<ItemGroup>
<_SmartIncludedFileSource Remove="@(_SmartExcludedFileSource)" />
</ItemGroup>
<!-- Calculates the relative target path for each item under the target template directory -->
<AssignIncludeTargetPaths Files="@(_SmartIncludedFileSource)">
<Output TaskParameter="AssignedFiles" ItemName="SmartTemplateContentWithTargetPath" />
</AssignIncludeTargetPaths>
</Target>
<!--
=======================================================================================================
Copies out of date template content (included or direct)
to the $(SmartTemplateIntermediateOutputPath) prior to zipping
=======================================================================================================
-->
<Target
Name="CopyOutOfDateSmartTemplateContent"
Condition="'@(SmartTemplateContentWithTargetPath)' != ''"
Inputs="@(SmartTemplateContentWithTargetPath)"
Outputs="@(SmartTemplateContentWithTargetPath->'$(SmartTemplateIntermediateOutputPath)%(TargetPath)')">
<Copy
SourceFiles="@(SmartTemplateContentWithTargetPath)"
DestinationFiles="@(SmartTemplateContentWithTargetPath->'$(SmartTemplateIntermediateOutputPath)%(TargetPath)')"
OverwriteReadOnlyFiles="true"
Retries="$(CopyRetryCount)"
RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
SkipUnchangedFiles="true">
<Output TaskParameter="DestinationFiles" ItemName="FileWrites" />
</Copy>
</Target>
<!--
=======================================================================================================
Zip the intermediate content, if changed
=======================================================================================================
-->
<Target Name="ZipSmartTemplateContent" Condition="'@(SmartVSTemplate)' != ''">
<ItemGroup>
<_SmartTemplateContent Include="$(SmartTemplateIntermediateOutputFullPath)%(SmartVSTemplate.RelativeDir)**\*.*">
<ZipRootDir>$([System.IO.Directory]::GetParent($(SmartTemplateIntermediateOutputFullPath)%(SmartVSTemplate.RelativeDir)).FullName)\</ZipRootDir>
<ZipFile>$([System.IO.Directory]::GetParent($(SmartTemplateIntermediateOutputFullPath)%(SmartVSTemplate.RelativeDir)).Parent.FullName)\%(SmartVSTemplate.Filename).zip</ZipFile>
</_SmartTemplateContent>
</ItemGroup>
<!--
The following VSSDK built-in task takes care of zipping a template. It doesn't do any pre or post-processing
of the .vstemplate, which is exactly what we want as we may have links, etc. This is the opposite of what
the built-in VSTemplate build action does, which mangles everything and breaks badly with linked files,
multi-project templates, etc.
It doesn't re-zip if files haven't changed also.
-->
<ZipItems Files="@(_SmartTemplateContent)"
Action="New"
ProjectPath="$(SmartTemplateIntermediateOutputFullPath)"
RootPath="%(_SmartTemplateContent.ZipRootDir)"
ZipFile="%(_SmartTemplateContent.ZipFile)">
<Output TaskParameter="ZipFile" ItemName="_SmartTemplateZip" />
</ZipItems>
</Target>
<!--
=======================================================================================================
Add as content to be included in the VSIX
=======================================================================================================
-->
<Target Name="AddSmartTemplateZip" Condition="'@(SmartVSTemplate)' != ''">
<ItemGroup>
<FileWrites Include="@(_SmartTemplateZip)" />
<Content Include="@(_SmartTemplateZip)">
<!-- This Link is used by the VSSDK target to set the VSIXSubPath directory where the item will be deployed/added to the vsix -->
<Link>$([System.IO.Directory]::GetParent(%(_SmartTemplateZip.FullPath)).FullName.Replace($(SmartTemplateIntermediateOutputFullPath), ''))\%(_SmartTemplateZip.Filename)%(_SmartTemplateZip.Extension)</Link>
<IncludeInVSIX>true</IncludeInVSIX>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<UseAssemblyName>false</UseAssemblyName>
</Content>
</ItemGroup>
</Target>
<Import Project="Clarius.VisualStudio.Tasks.tasks"/>
</Project>