-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rids #93
Rids #93
Changes from all commits
20be492
99f7ef8
b7965ca
6f34b43
b65ada9
834f49d
475d07d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
||
<PropertyGroup> | ||
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects> | ||
</PropertyGroup> | ||
|
||
|
||
<Target Name="_ExtrasFilterRidFromRestore" AfterTargets="_GetRestoreTargetFrameworksOutput" BeforeTargets="_GenerateRestoreProjectSpec"> | ||
|
||
<ItemGroup> | ||
|
||
<_SdkUniqueTfms /> | ||
|
||
<!-- Get the TFM's that contain an RID --> | ||
<_SdkFilteredTfms Include="@(_RestoreTargetFrameworksOutputFiltered)" | ||
Condition="$([MSBuild]::ValueOrDefault('%(Identity)', '').Contains('+')) and !$([MSBuild]::ValueOrDefault('%(Identity)', '').Contains('portable'))" | ||
Replacement="$([MSBuild]::ValueOrDefault('%(Identity)', '').Substring(0, $([MSBuild]::ValueOrDefault('%(Identity)', '').IndexOf('+'))) )" | ||
|
||
/> | ||
|
||
<!-- Remove them from the filtered list since NuGet doesn't know about it here --> | ||
<_RestoreTargetFrameworksOutputFiltered Remove="@(_SdkFilteredTfms)" /> | ||
</ItemGroup> | ||
|
||
<RemoveDuplicates | ||
Inputs="@(_SdkFilteredTfms->'%(Replacement)')"> | ||
<Output | ||
TaskParameter="Filtered" | ||
ItemName="_SdkUniqueTfms" /> | ||
</RemoveDuplicates> | ||
|
||
<ItemGroup> | ||
<_RestoreTargetFrameworksOutputFiltered Include="@(_SdkUniqueTfms)" /> | ||
</ItemGroup> | ||
</Target> | ||
|
||
<Target Name="_ExtrasFilterRidFromGraphEntry" AfterTargets="_GenerateProjectRestoreGraphCurrentProject;_GenerateProjectRestoreGraphAllFrameworks" BeforeTargets="_GenerateRestoreDependencies"> | ||
|
||
<ItemGroup> | ||
<_RestoreGraphEntry Update="@(_RestoreGraphEntry)" | ||
Condition="$([MSBuild]::ValueOrDefault('%(_RestoreGraphEntry.TargetFramework)', '').Contains('+')) and !$([MSBuild]::ValueOrDefault('%(_RestoreGraphEntry.TargetFramework)', '').Contains('portable'))" | ||
OriginalTargetFramework="%(_RestoreGraphEntry.TargetFramework)" | ||
TargetFramework="$([MSBuild]::ValueOrDefault('%(_RestoreGraphEntry.TargetFramework)', '').Substring(0, $([MSBuild]::ValueOrDefault('%(_RestoreGraphEntry.TargetFramework)', '').IndexOf('+'))) )" | ||
|
||
/> | ||
<_RestoreGraphEntry Update="@(_RestoreGraphEntry)" | ||
Condition="$([MSBuild]::ValueOrDefault('%(_RestoreGraphEntry.TargetFrameworks)', '').Contains('+')) and !$([MSBuild]::ValueOrDefault('%(_RestoreGraphEntry.TargetFrameworks)', '').Contains('portable'))" | ||
OriginalTargetFrameworks="%(_RestoreGraphEntry.TargetFrameworks)" | ||
TargetFrameworks="$([MSBuild]::ValueOrDefault('%(_RestoreGraphEntry.TargetFrameworks)', '').Substring(0, $([MSBuild]::ValueOrDefault('%(_RestoreGraphEntry.TargetFrameworks)', '').IndexOf('+'))) )" | ||
|
||
/> | ||
</ItemGroup> | ||
</Target> | ||
|
||
|
||
|
||
<PropertyGroup> | ||
<_SdkTaskFactoryType Condition="'$(MSBuildRuntimeType)' == 'Full'">CodeTaskFactory</_SdkTaskFactoryType> | ||
<_SdkTaskFactoryType Condition="'$(MSBuildRuntimeType)' == 'Core'">RoslynTaskFactory</_SdkTaskFactoryType> | ||
<_SdkTaskAssemblyFileName Condition="'$(MSBuildRuntimeType)' == 'Full'">$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll</_SdkTaskAssemblyFileName> | ||
<_SdkTaskAssemblyFileName Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildBinPath)\Microsoft.Build.Tasks.Core.dll</_SdkTaskAssemblyFileName> | ||
</PropertyGroup> | ||
|
||
|
||
<UsingTask TaskName="_ExtrasUpdateTargetsFile" | ||
TaskFactory="$(_SdkTaskFactoryType)" | ||
AssemblyFile="$(_SdkTaskAssemblyFileName)"> | ||
<ParameterGroup> | ||
<ItemMap ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" /> | ||
<InputFile ParameterType="System.String" Required="true" /> | ||
<OutputFile ParameterType="System.String" Required="true" /> | ||
</ParameterGroup> | ||
<Task> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Using Namespace="System" /> | ||
<Using Namespace="System.IO" /> | ||
<Using Namespace="System.Linq" /> | ||
<Using Namespace="System.Xml.Linq" /> | ||
<Code Type="Fragment" Language="C#"> | ||
<![CDATA[ | ||
var doc = XDocument.Load(File.OpenText(InputFile)); | ||
var ns = doc.Root.GetDefaultNamespace(); | ||
|
||
// Escape this to avoid MSBuild issues | ||
var tf = "$" + "(TargetFramework)"; | ||
|
||
// The input has the source in the items | ||
var tfms = ItemMap.GroupBy(i => i.GetMetadata("TargetFramework"), i => i.ItemSpec); | ||
|
||
foreach (var tfm in tfms) | ||
{ | ||
var targetString = string.Format("'{0}' == '{1}'", tf, tfm.Key); | ||
|
||
var group = doc.Root.Elements(ns + "ImportGroup") | ||
.FirstOrDefault(ele => ele.Attribute("Condition").Value.Contains(targetString)); | ||
|
||
if (group != null) | ||
{ | ||
var clauses = tfm.Select(t => string.Format("'{0}' == '{1}'",tf, t)); | ||
var replacementString = string.Join(" OR ", clauses); | ||
replacementString = string.Format("( {0} )", replacementString); | ||
|
||
group.Attribute("Condition").Value = group.Attribute("Condition").Value.Replace(targetString, replacementString); | ||
} | ||
|
||
} | ||
|
||
doc.Save(OutputFile); | ||
]]> | ||
</Code> | ||
</Task> | ||
</UsingTask> | ||
|
||
|
||
<!-- | ||
Copy the main targets to make sure we generate the restore file first | ||
--> | ||
<Target Name="_SdkRestoreOriginal" DependsOnTargets="_GenerateRestoreGraph"> | ||
|
||
<!-- Drop any duplicate items --> | ||
<RemoveDuplicates | ||
Inputs="@(_RestoreGraphEntry)"> | ||
<Output | ||
TaskParameter="Filtered" | ||
ItemName="_RestoreGraphEntryFiltered" /> | ||
</RemoveDuplicates> | ||
|
||
<!-- Call restore --> | ||
<RestoreTask | ||
RestoreGraphItems="@(_RestoreGraphEntryFiltered)" | ||
RestoreDisableParallel="$(RestoreDisableParallel)" | ||
RestoreNoCache="$(RestoreNoCache)" | ||
RestoreIgnoreFailedSources="$(RestoreIgnoreFailedSources)" | ||
RestoreRecursive="$(RestoreRecursive)" | ||
RestoreForce="$(RestoreForce)" | ||
HideWarningsAndErrors="$(HideWarningsAndErrors)"/> | ||
</Target> | ||
|
||
|
||
|
||
<Target Name="_ExtrasFixRestoreFiles" | ||
Condition="@(_RestoreGraphEntry->'%(OriginalTargetFrameworks)') != '' or @(_RestoreGraphEntry->'%(OriginalTargetFramework)') != ''" | ||
BeforeTargets="Restore" AfterTargets="_GenerateProjectRestoreGraph" DependsOnTargets="_SdkRestoreOriginal"> | ||
|
||
<ItemGroup> | ||
<_SdkTfmToOriginalMapTmp Include="@(_RestoreGraphEntry->'%(OriginalTargetFrameworks)')" TargetFramework="%(_RestoreGraphEntry.TargetFrameworks)" KeepMetadata="TargetFramework" /> | ||
<_SdkTfmToOriginalMapTmp Include="@(_RestoreGraphEntry->'%(OriginalTargetFramework)')" TargetFramework="%(_RestoreGraphEntry.TargetFramework)" KeepMetadata="TargetFramework" /> | ||
</ItemGroup> | ||
|
||
<RemoveDuplicates | ||
Inputs="@(_SdkTfmToOriginalMapTmp)"> | ||
<Output | ||
TaskParameter="Filtered" | ||
ItemName="_SdkTfmToOriginal" /> | ||
</RemoveDuplicates> | ||
|
||
|
||
<PropertyGroup> | ||
<_SdkFileLocation>$(MSBuildProjectExtensionsPath)</_SdkFileLocation> | ||
<_SdkPropsFileLocation>$(_SdkFileLocation)$(MSBuildProjectFile).nuget.g.props</_SdkPropsFileLocation> | ||
<_SdkTargetsFileLocation>$(_SdkFileLocation)$(MSBuildProjectFile).nuget.g.targets</_SdkTargetsFileLocation> | ||
<_SdkTargetsFileLocationOut>$(_SdkFileLocation)$(MSBuildProjectFile).extras.g.targets</_SdkTargetsFileLocationOut> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a great use of my MSBuildProjectExtensions feature! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was really a hack since I couldn't directly manipulate the generated file....access denied because msbuild already had a lock on it :P |
||
<_SdkPropsFileLocationOut>$(_SdkFileLocation)$(MSBuildProjectFile).extras.g.props</_SdkPropsFileLocationOut> | ||
</PropertyGroup> | ||
|
||
<_ExtrasUpdateTargetsFile | ||
ItemMap="@(_SdkTfmToOriginal)" | ||
InputFile="$(_SdkTargetsFileLocation)" | ||
OutputFile="$(_SdkTargetsFileLocationOut)" | ||
Condition="Exists('$(_SdkTargetsFileLocation)')" | ||
/> | ||
|
||
<_ExtrasUpdateTargetsFile | ||
ItemMap="@(_SdkTfmToOriginal)" | ||
InputFile="$(_SdkPropsFileLocation)" | ||
OutputFile="$(_SdkPropsFileLocationOut)" | ||
Condition="Exists('$(_SdkPropsFileLocation)')" | ||
/> | ||
|
||
|
||
</Target> | ||
|
||
</Project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can set
Evaluate="False"
on the<Task />
element above to have MSBuild not evaluate the task body.https://docs.microsoft.com/en-us/visualstudio/msbuild/taskbody-element-msbuild