Skip to content

Commit 93bd41a

Browse files
Treat non-web apps as first class, not requiring appSettings hack. (#131)
1 parent e352f9a commit 93bd41a

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

RoslynCodeProviderTest/ProviderOptionsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void DefaultSettings()
3434
{
3535
IProviderOptions opts = CompilationUtil.GetProviderOptionsFor(".fakevb");
3636
Assert.IsNotNull(opts);
37-
Assert.AreEqual<string>(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"bin\roslyn"), opts.CompilerFullPath); // Would include csc.exe or vbc.exe if the extension we searched for wasn't fake.
37+
Assert.AreEqual<string>(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"roslyn"), opts.CompilerFullPath); // Would include csc.exe or vbc.exe if the extension we searched for wasn't fake.
3838
Assert.AreEqual<int>(IsDev ? 15 * 60 : 10, opts.CompilerServerTimeToLive); // 10 in Production. 900 in a "dev" environment.
3939
Assert.IsTrue(opts.UseAspNetSettings); // Default is false... except through the GetProviderOptionsFor factory method we used here.
4040
Assert.IsFalse(opts.WarnAsError);
@@ -143,7 +143,7 @@ public void TTL_MustBeInteger()
143143
Environment.SetEnvironmentVariable("VBCSCOMPILER_TTL", null);
144144

145145
Assert.IsNotNull(opts);
146-
Assert.AreEqual<string>(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"bin\roslyn"), opts.CompilerFullPath); // Would include csc.exe or vbc.exe if the extension we searched for wasn't fake.
146+
Assert.AreEqual<string>(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"roslyn"), opts.CompilerFullPath); // Would include csc.exe or vbc.exe if the extension we searched for wasn't fake.
147147
Assert.AreEqual<int>(IsDev ? 15 * 60 : 10, opts.CompilerServerTimeToLive); // 10 in Production. 900 in a "dev" environment.
148148
Assert.IsTrue(opts.UseAspNetSettings); // Default is false... except through the GetProviderOptionsFor factory method we used here.
149149
Assert.IsFalse(opts.WarnAsError);

src/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/Util/CompilationUtil.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static IProviderOptions GetProviderOptionsFor(string fileExt)
4646
if (String.IsNullOrEmpty(compilerFullPath))
4747
options.TryGetValue("CompilerLocation", out compilerFullPath);
4848
if (String.IsNullOrEmpty(compilerFullPath))
49-
compilerFullPath = CompilerFullPath(@"bin\roslyn");
49+
compilerFullPath = CompilerDefaultPath();
5050

5151
if (fileExt.Equals(".cs", StringComparison.InvariantCultureIgnoreCase))
5252
compilerFullPath = Path.Combine(compilerFullPath, "csc.exe");
@@ -143,9 +143,18 @@ internal static void PrependCompilerOption(CompilerParameters compilParams, stri
143143
}
144144
}
145145

146-
internal static string CompilerFullPath(string relativePath)
146+
internal static string CompilerDefaultPath()
147147
{
148-
string compilerFullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, relativePath);
148+
string webPath = @"bin\roslyn";
149+
string appPath = @"roslyn";
150+
151+
// Check bin folder first
152+
string compilerFullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, webPath);
153+
154+
// Then appdomain base
155+
if (!File.Exists(compilerFullPath))
156+
compilerFullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, appPath);
157+
149158
return compilerFullPath;
150159
}
151160

src/Packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/build/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
<!-- But when OutDir is specified given and is different from the above, copy to OutDir as well -->
3030
<ItemGroup Condition="'$(WebProjectOutputDir)' != ''">
3131
<RoslynToolsDestinations Include="$(WebProjectOutputDir)\bin\roslyn" />
32-
<RoslynToolsDestinations Condition="'$(RoslynCopyToOutDir)' == 'true' AND '$(OutDir)' != '$(WebProjectOutputDir)'" Include="$(OutDir)\bin\roslyn" />
32+
<RoslynToolsDestinations Condition="'$(RoslynCopyToOutDir)' == 'true' AND '$(OutDir)' != '$(WebProjectOutputDir)'" Include="$(OutDir)\roslyn" />
3333
</ItemGroup>
3434
<ItemGroup Condition="'$(WebProjectOutputDir)' == ''">
35-
<RoslynToolsDestinations Include="$(OutputPath)\bin\roslyn" />
35+
<RoslynToolsDestinations Include="$(OutputPath)\roslyn" />
3636
<RoslynToolsDestinations Condition="'$(RoslynCopyToOutDir)' == 'true' AND '$(OutDir)' != '$(OutputPath)'" Include="$(OutDir)\roslyn" />
3737
</ItemGroup>
3838
</Target>

0 commit comments

Comments
 (0)