我想在我正在.NET Core中编写的.NET控制台应用程序中使用Razor作为模板引擎.
我遇到的独立Razor引擎(RazorEngine,RazorTemplates)都需要完整的.NET.我正在寻找适用于.NET Core的解决方案.
这是我自己的定制nuget包,我还没有发布并在本地测试.
nuget包由dll文件和nuspec文件组成,如下所示.
<?xml version="1.0"?>
<package >
<metadata>
<id>MyLib</id>
<version>1.0.0</version>
<authors>Author</authors>
<owners>Owner</owners>
<licenseUrl>license url</licenseUrl>
<projectUrl>project url</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>some description</copyright>
<tags>Tag1 Tage2</tags>
</metadata>
<files>
<file src="bin\Debug\netstandard1.4\*.dll" target="lib" />
<file src="bin\Debug\netstandard1.4\*.pdb" target="lib" />
</files>
</package>
Run Code Online (Sandbox Code Playgroud)
我已将nupkg文件复制到某个位置并将其添加到
Visual studio Tools -> Options -> Packages -> sources directory
Run Code Online (Sandbox Code Playgroud)
错误:
Package MyLib 1.0.0 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package MyLib 1.0.0 supports: net (.NETFramework,Version=v0.0)
Package restore failed. Rolling back package changes for 'WebApplication1'.
Run Code Online (Sandbox Code Playgroud)
不确定如何解决问题或查找更多信息.
更多信息
dll文件是使用模板(.Net Framework 4.5.2)创建的
Templates -> Visual C# -> .NET …Run Code Online (Sandbox Code Playgroud) 我正在使用带有C#的.NETCore,当我这样做时,dotnet restore它给出了以下错误:
PS C:\ workspace\Arbitrator> dotnet restore
C:\ workspace\Arbitrator\Arbitrator.csproj:警告NU1701:使用'.NETFramework,Version = v4.6.1'恢复包'PusherClient 0.5.0'而不是项目目标框架'.NETCoreApp,Version = v2.0'.这可能会导致兼容性问题.C:\ workspace\Arbitrator\Arbitrator.csproj:警告NU1701:程序包'WebSocket4Net 0.14.1'使用'.NETFramework,Version = v4.6.1'而不是项目目标框架'.NETCoreApp,Version = v2.0'进行了恢复.这可能会导致兼容性问题.
问题中的这个包是PusherClient,我只是按照块文件导入它,我该如何修复这个警告?
我刚刚开始研究.Net Core,我没有看到经典资源和任何看似资源的东西.在经典的.Net类库中,我能够将带有一些脚本的文本过滤添加到我的项目中,而不是将这些文件添加到项目的资源中.之后我可以通过以下方式轻松使用它:
Connection.Execure(Properties.Resources.MySuperScript);
Run Code Online (Sandbox Code Playgroud)
我看到.Net Core库中没有这样的功能,至少我看不到.在.Net Core中是否有替代方法可以将一些静态数据存储为库中的嵌入式资源?如果它存在,如何使用它?
我发现了一些文章如何在ASP.NET中将视图返回到字符串,但无法转换为能够使用.NET Core运行它
public static string RenderViewToString(this Controller controller, string viewName, object model)
{
var context = controller.ControllerContext;
if (string.IsNullOrEmpty(viewName))
viewName = context.RouteData.GetRequiredString("action");
var viewData = new ViewDataDictionary(model);
using (var sw = new StringWriter())
{
var viewResult = ViewEngines.Engines.FindPartialView(context, viewName);
var viewContext = new ViewContext(context, viewResult.View, viewData, new TempDataDictionary(), sw);
viewResult.View.Render(viewContext, sw);
return sw.GetStringBuilder().ToString();
}
}
Run Code Online (Sandbox Code Playgroud)
假设能够使用以下控制器从控制器调用:
var strView = this.RenderViewToString("YourViewName", yourModel);
Run Code Online (Sandbox Code Playgroud)
当我尝试将上述内容运行到.NET Core时,我遇到了很多编译错误.
我试图将其转换为使用.NET Core,但失败了,任何人都可以帮助提及所需的using ..和所需"dependencies": {
"Microsoft.AspNetCore.Mvc": "1.1.0",
...
},的project.json.
其他一些示例代码在这里, …
我想知道NuGet.Config文件位于Visual Studio 2017项目中的哪个位置?我试图在项目的根目录中创建自己的NuGet.Config文件,但是我没有找到任何新的存储库(NuGet源代码).有人有任何想法吗?
这是我试图为我的.Net Core项目实现的文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="AspNetCore" value="https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json" />
<add key="AspNetCoreTools" value="https://dotnet.myget.org/F/aspnetcore-tools/api/v3/index.json" />
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
Run Code Online (Sandbox Code Playgroud) 我使用Visual Studio 2017(Community Edition)创建了一个ASP.NET Core Web API应用程序.我可以使用Visual Studio成功发布到Azure App Service.
我现在想要使用VSTS设置CI/CD.我使用了Visual Studio中的"配置持续交付"选项,该选项在VSTS中创建了一个项目并创建了一个构建定义.我必须在VSTS中基于'ASP.NET Core'模板创建一个新的构建定义,以避免Nuget恢复错误.现在构建解决方案并运行测试,但"发布"任务完成并发出警告 -
##[warning]No web project was found in the repository. Web projects are identified by the presence of either a web.config file or wwwroot folder in the directory.
Run Code Online (Sandbox Code Playgroud)
"发布工件"任务也有类似的警告 -
##[warning]Directory 'd:\a\1\a' is empty. Nothing will be added to build artifact 'drop'.
Run Code Online (Sandbox Code Playgroud)
显然,构建不会产生任何伪影.
我是否需要将任何构建任务添加到默认的ASP.NET Core构建模板中?如何使用VSTS将我的Web API发布到Azure?
azure continuous-deployment .net-core azure-devops asp.net-core
拥有以下服务构造函数
public class Service : IService
{
public Service(IOtherService service1, IAnotherOne service2, string arg)
{
}
}
Run Code Online (Sandbox Code Playgroud)
使用.NET Core IOC机制传递参数有哪些选择?
_serviceCollection.AddSingleton<IOtherService , OtherService>();
_serviceCollection.AddSingleton<IAnotherOne , AnotherOne>();
_serviceCollection.AddSingleton<IService>(x=>new Service( _serviceCollection.BuildServiceProvider().GetService<IOtherService>(), _serviceCollection.BuildServiceProvider().GetService<IAnotherOne >(), "" ));
Run Code Online (Sandbox Code Playgroud)
还有其他方法吗?
c# dependency-injection ioc-container .net-core asp.net-core
这是真的ApiController吗," 会在.NET Core中被弃用"吗?我真的需要专业的见解.因为我打算在新项目中使用它.
.net-core ×10
c# ×8
asp.net-core ×5
nuget ×3
.net ×2
razor ×2
asp.net ×1
asp.net-mvc ×1
azure ×1
azure-devops ×1