-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip non-nugetized projects when nugetizer runs for solution
Rather than failing ungracefully, just skip those project where we can safely detect nugetizer isn't installed. Fixes #107
- Loading branch information
Showing
4 changed files
with
99 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
static class EmbeddedResource | ||
{ | ||
static readonly string baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
|
||
public static string GetContent(string relativePath) | ||
{ | ||
var filePath = Path.Combine(baseDir, Path.GetFileName(relativePath)); | ||
if (File.Exists(filePath)) | ||
return File.ReadAllText(filePath); | ||
|
||
var baseName = Assembly.GetExecutingAssembly().GetName().Name; | ||
var resourceName = relativePath | ||
.TrimStart('.') | ||
.Replace(Path.DirectorySeparatorChar, '.') | ||
.Replace(Path.AltDirectorySeparatorChar, '.'); | ||
|
||
var manifestResourceName = Assembly.GetExecutingAssembly() | ||
.GetManifestResourceNames().FirstOrDefault(x => x.EndsWith(resourceName)); | ||
|
||
if (string.IsNullOrEmpty(manifestResourceName)) | ||
throw new InvalidOperationException($"Did not find required resource ending in '{resourceName}' in assembly '{baseName}'."); | ||
|
||
using var stream = Assembly.GetExecutingAssembly() | ||
.GetManifestResourceStream(manifestResourceName); | ||
|
||
if (stream == null) | ||
throw new InvalidOperationException($"Did not find required resource '{manifestResourceName}' in assembly '{baseName}'."); | ||
|
||
using var reader = new StreamReader(stream); | ||
return reader.ReadToEnd(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Target Name="RemoveNonNuGetized" BeforeTargets="GetPackageContents"> | ||
<MSBuild Properties="BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" | ||
BuildInParallel="True" | ||
SkipNonexistentProjects="%(ProjectReference.SkipNonexistentProjects)" | ||
Targets="GetTargetPath" | ||
Projects="@(ProjectReference)"> | ||
<Output TaskParameter="TargetOutputs" ItemName="ReferencedProjectTargetPath" /> | ||
</MSBuild> | ||
<ItemGroup> | ||
<NuGetizedTargetPath Include="@(ReferencedProjectTargetPath -> WithMetadataValue('IsNuGetized', 'true'))" /> | ||
<NonNuGetizedTargetPath Include="@(ReferencedProjectTargetPath)" Exclude="@(NuGetizedTargetPath)" /> | ||
<ProjectReference Remove="@(NonNuGetizedTargetPath -> '%(MSBuildSourceProjectFile)')" /> | ||
</ItemGroup> | ||
</Target> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters