是否可以在 C# Interactive 中使用来自 Web 项目的代码?
Is it possible to use code from a Web project in C# Interactive?
我想在 Visual Studio 2017 上使用 C# Interactive 到 运行 我创建的使用 ASP.NET核心。在传统的 class 库项目中,我可以右键单击项目并选择 Initialize Interactive with Project 以使用我的项目中的 classes C# 交互式 window.
右击我的ASP.NET核心项目,我没有这个选项。有什么方法可以在 C# Interactive 中使用此项目中的 classes 吗?
如果重要的话,我想在 C# Interactive 中使用的 classes 不直接与 ASP.NET Core 交互;它们只是带有方法的数据容器。可能可以将它们移动到解决方案中单独的 class 库项目,但我想知道是否可以先将它们保留在 ASP.NET 核心项目中。
我的.csproj
:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="EntityFramework" Version="6.1.3" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNet.Mvc" Version="5.2.3" />
<PackageReference Include="Microsoft.AspNet.Razor" Version="3.2.3" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.0.0" />
<PackageReference Include="RazorEngine" Version="3.10.0" />
</ItemGroup>
</Project>
只需打开 C# interactive window 并输入
#r "full path to dll\exe with your asp.net core project"
然后您可以照常使用您的 类。
请注意,如果您的项目以 .NET Core 为目标 - 它可能无法按预期(或根本无法)工作,因为据我所知 - C# interactive 目前在完整的 .NET Framework 下运行。但是,在您的情况下,您的项目也在完整的 .NET (<TargetFramework>net461</TargetFramework>
) 下,所以您应该没问题。
我想在 Visual Studio 2017 上使用 C# Interactive 到 运行 我创建的使用 ASP.NET核心。在传统的 class 库项目中,我可以右键单击项目并选择 Initialize Interactive with Project 以使用我的项目中的 classes C# 交互式 window.
右击我的ASP.NET核心项目,我没有这个选项。有什么方法可以在 C# Interactive 中使用此项目中的 classes 吗?
如果重要的话,我想在 C# Interactive 中使用的 classes 不直接与 ASP.NET Core 交互;它们只是带有方法的数据容器。可能可以将它们移动到解决方案中单独的 class 库项目,但我想知道是否可以先将它们保留在 ASP.NET 核心项目中。
我的.csproj
:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="EntityFramework" Version="6.1.3" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNet.Mvc" Version="5.2.3" />
<PackageReference Include="Microsoft.AspNet.Razor" Version="3.2.3" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.0.0" />
<PackageReference Include="RazorEngine" Version="3.10.0" />
</ItemGroup>
</Project>
只需打开 C# interactive window 并输入
#r "full path to dll\exe with your asp.net core project"
然后您可以照常使用您的 类。
请注意,如果您的项目以 .NET Core 为目标 - 它可能无法按预期(或根本无法)工作,因为据我所知 - C# interactive 目前在完整的 .NET Framework 下运行。但是,在您的情况下,您的项目也在完整的 .NET (<TargetFramework>net461</TargetFramework>
) 下,所以您应该没问题。