Skip to content
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

Fix: RT0999: Could not load file or assembly 'System.ServiceModel.Primitives' #279

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions Reinforced.Typings.Integrate/RtCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Reinforced.Typings.Cli;
Expand Down Expand Up @@ -106,6 +107,15 @@ public override string ToolExe
get; set;
}

/// <summary>
/// By default `true`, you can disable it if caused any problems.
/// Exchange reference assemblies to their corresponding executable pairs, if found.
/// Drop reference assemblies otherwise.
/// See:
/// https://github.com/reinforced/Reinforced.Typings/issues/227
/// </summary>
public bool ExchangeReferenceAssemblies { get; set; } = true;

protected override string GenerateFullPathToTool()
{
if (IsCore)
Expand Down Expand Up @@ -241,11 +251,34 @@ private string FixTargetPath(string path)
return path;
}

private IEnumerable<string> GetReferenceAssemblyPaths()
{
var refRegex = new Regex(@"[\\/]+ref[\\/]+");

return (References ?? Array.Empty<ITaskItem>())
.Select(c => c.ItemSpec)
.Select(DoExchangeReferenceAssemblies)
.Where(x => x != null);

string DoExchangeReferenceAssemblies(string assemblyPath)
{
if (!ExchangeReferenceAssemblies)
{
return assemblyPath;
}
if (refRegex.IsMatch(assemblyPath))
{
var libAssembly = refRegex.Replace(assemblyPath, "/lib/");
return File.Exists(libAssembly) ? libAssembly : null;
}
return assemblyPath;
}
}

private void PutReferencesToTempFile(TextWriter tw)
{
if (References == null) return;
foreach (var rf in References.Select(c => c.ItemSpec))
var referenceAssemblyPaths = GetReferenceAssemblyPaths();
foreach (var rf in referenceAssemblyPaths)
{
tw.WriteLine(rf);
}
Expand Down
1 change: 1 addition & 0 deletions stuff/Reinforced.Typings.targets
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
DocumentationFilePath="$(MSBuildProjectDirectory)\$(DocumentationFile)"
ConfigurationMethod="$(RtConfigurationMethod)"
SuppressedWarnings="$(RtSuppress)"
ExchangeReferenceAssemblies="$(RtExchangeReferenceAssemblies)"
/>
<MSBuild Projects="$(MSBuildProjectFullPath)" Properties="INeedThis=JustToRebuildTypescripts;BuildingProject=true" Targets="CompileTypeScript" Condition="'$(TypeScriptTarget)' != '' AND '@(ConfigFiles)' == ''" />
<MSBuild Projects="$(MSBuildProjectFullPath)" Properties="INeedThis=JustToRebuildTypescripts;BuildingProject=true" Targets="CompileTypeScriptWithTSConfig" Condition="'$(TypeScriptTarget)' != '' AND '@(ConfigFiles)' != ''" />
Expand Down