Skip to content
Merged
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
25 changes: 21 additions & 4 deletions AspNetCore.SassCompiler/SassCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,34 @@ internal static Process CreateSassProcess(string arguments)

internal static (string Filename, string Snapshot) GetSassCommand()
{
var (exePath, snapshotPath) = GetExeAndSnapshotPath();

var attribute = Assembly.GetEntryAssembly()?.GetCustomAttributes<SassCompilerAttribute>().FirstOrDefault();

if (attribute != null)
return (attribute.SassBinary, string.IsNullOrWhiteSpace(attribute.SassSnapshot) ? "" : $"\"{attribute.SassSnapshot}\"");

var assemblyLocation = typeof(SassCompilerHostedService).Assembly.Location;
{
if (exePath != null)
{
// When the runtime compiler is used, the machine the code is compiled on can be different from the
// machine it runs on. So we check whether the filepath ends with the expected path for this platform,
// if not we fall back to searching in the assembly location.
if (attribute.SassBinary.EndsWith(exePath)
&& attribute.SassSnapshot.EndsWith(snapshotPath))
{
return (attribute.SassBinary, string.IsNullOrWhiteSpace(attribute.SassSnapshot) ? "" : $"\"{attribute.SassSnapshot}\"");
}
}
else
{
return (attribute.SassBinary, string.IsNullOrWhiteSpace(attribute.SassSnapshot) ? "" : $"\"{attribute.SassSnapshot}\"");
}
}

var (exePath, snapshotPath) = GetExeAndSnapshotPath();
if (exePath == null)
return (null, null);

var assemblyLocation = typeof(SassCompilerHostedService).Assembly.Location;

var directory = Path.GetDirectoryName(assemblyLocation);
while (!string.IsNullOrEmpty(directory) && directory != "/")
{
Expand Down
23 changes: 12 additions & 11 deletions AspNetCore.SassCompiler/build/AspNetCore.SassCompiler.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@

<SassCompilerTasksAssembly Condition=" '$(SassCompilerTasksAssembly)' == '' ">$(MSBuildThisFileDirectory)..\lib\netstandard2.0\AspNetCore.SassCompiler.Tasks.dll</SassCompilerTasksAssembly>

<SassCompilerEnableWatcher Condition="'$(SassCompilerEnableWatcher)' == ''">$(SassCompilerIncludeRuntime)</SassCompilerEnableWatcher>
<SassCompilerEnableWatcher Condition="'$(SassCompilerEnableWatcher)' == '' AND '$(RuntimeIdentifier)' == 'browser-wasm'">false</SassCompilerEnableWatcher>
<SassCompilerEnableWatcher Condition="'$(SassCompilerEnableWatcher)' == '' AND '$(Configuration)' == 'Release'">false</SassCompilerEnableWatcher>
<SassCompilerEnableWatcher Condition="'$(SassCompilerEnableWatcher)' == '' AND '$(OutputType)' == 'Library'">false</SassCompilerEnableWatcher>

<SassCompilerConfiguration Condition="'$(SassCompilerConfiguration)' == ''">$(Configuration)</SassCompilerConfiguration>
<SassCompilerConfiguration Condition="'$(SassCompilerConfiguration)' == ''">Debug</SassCompilerConfiguration>

<SassCompilerRuntimeCopyToPublishDirectory>Never</SassCompilerRuntimeCopyToPublishDirectory>
</PropertyGroup>

<ItemGroup Condition="'$(SassCompilerEnableWatcher)' != 'false'">
Expand All @@ -42,16 +43,16 @@
</ItemGroup>

<ItemGroup Condition="'$(SassCompilerEnableWatcher)' != 'false'">
<None Include="$(MSBuildThisFileDirectory)..\runtimes\win-x64\src\dart.exe" Link="runtimes\win-x64\src\dart.exe" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="Never" />
<None Include="$(MSBuildThisFileDirectory)..\runtimes\win-x64\src\sass.snapshot" Link="runtimes\win-x64\src\sass.snapshot" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="Never" />
<None Include="$(MSBuildThisFileDirectory)..\runtimes\linux-x64\src\dart" Link="runtimes\linux-x64\src\dart" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="Never" />
<None Include="$(MSBuildThisFileDirectory)..\runtimes\linux-x64\src\sass.snapshot" Link="runtimes\linux-x64\src\sass.snapshot" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="Never" />
<None Include="$(MSBuildThisFileDirectory)..\runtimes\linux-arm64\src\dart" Link="runtimes\linux-arm64\src\dart" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="Never" />
<None Include="$(MSBuildThisFileDirectory)..\runtimes\linux-arm64\src\sass.snapshot" Link="runtimes\linux-arm64\src\sass.snapshot" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="Never" />
<None Include="$(MSBuildThisFileDirectory)..\runtimes\osx-x64\src\dart" Link="runtimes\osx-x64\src\dart" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="Never" />
<None Include="$(MSBuildThisFileDirectory)..\runtimes\osx-x64\src\sass.snapshot" Link="runtimes\osx-x64\src\sass.snapshot" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="Never" />
<None Include="$(MSBuildThisFileDirectory)..\runtimes\osx-arm64\src\dart" Link="runtimes\osx-arm64\src\dart" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="Never" />
<None Include="$(MSBuildThisFileDirectory)..\runtimes\osx-arm64\src\sass.snapshot" Link="runtimes\osx-arm64\src\sass.snapshot" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="Never" />
<None Include="$(MSBuildThisFileDirectory)..\runtimes\win-x64\src\dart.exe" Link="runtimes\win-x64\src\dart.exe" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="$(SassCompilerRuntimeCopyToPublishDirectory)" />
<None Include="$(MSBuildThisFileDirectory)..\runtimes\win-x64\src\sass.snapshot" Link="runtimes\win-x64\src\sass.snapshot" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="$(SassCompilerRuntimeCopyToPublishDirectory)" />
<None Include="$(MSBuildThisFileDirectory)..\runtimes\linux-x64\src\dart" Link="runtimes\linux-x64\src\dart" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="$(SassCompilerRuntimeCopyToPublishDirectory)" />
<None Include="$(MSBuildThisFileDirectory)..\runtimes\linux-x64\src\sass.snapshot" Link="runtimes\linux-x64\src\sass.snapshot" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="$(SassCompilerRuntimeCopyToPublishDirectory)" />
<None Include="$(MSBuildThisFileDirectory)..\runtimes\linux-arm64\src\dart" Link="runtimes\linux-arm64\src\dart" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="$(SassCompilerRuntimeCopyToPublishDirectory)" />
<None Include="$(MSBuildThisFileDirectory)..\runtimes\linux-arm64\src\sass.snapshot" Link="runtimes\linux-arm64\src\sass.snapshot" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="$(SassCompilerRuntimeCopyToPublishDirectory)" />
<None Include="$(MSBuildThisFileDirectory)..\runtimes\osx-x64\src\dart" Link="runtimes\osx-x64\src\dart" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="$(SassCompilerRuntimeCopyToPublishDirectory)" />
<None Include="$(MSBuildThisFileDirectory)..\runtimes\osx-x64\src\sass.snapshot" Link="runtimes\osx-x64\src\sass.snapshot" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="$(SassCompilerRuntimeCopyToPublishDirectory)" />
<None Include="$(MSBuildThisFileDirectory)..\runtimes\osx-arm64\src\dart" Link="runtimes\osx-arm64\src\dart" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="$(SassCompilerRuntimeCopyToPublishDirectory)" />
<None Include="$(MSBuildThisFileDirectory)..\runtimes\osx-arm64\src\sass.snapshot" Link="runtimes\osx-arm64\src\sass.snapshot" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="$(SassCompilerRuntimeCopyToPublishDirectory)" />
</ItemGroup>

<ItemGroup Condition="'$(SassCompilerEnableWatcher)' == 'false'">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<Project>

<PropertyGroup Condition="'$(SassCompilerIncludeRuntime)' == 'true'">
<SassCompilerEnableWatcher>$(SassCompilerIncludeRuntime)</SassCompilerEnableWatcher>
<SassCompilerRuntimeCopyToPublishDirectory>PreserveNewest</SassCompilerRuntimeCopyToPublishDirectory>
</PropertyGroup>

<ItemGroup>
<UpToDateCheckInput Include="**/*.scss" />
</ItemGroup>

<UsingTask TaskName="AspNetCore.SassCompiler.CompileSass"
AssemblyFile="$(SassCompilerTasksAssembly)" />

Expand Down