简体   繁体   English

ASP.NET 5类库-Nuget包Web.Config转换

[英]ASP.NET 5 Class Library - Nuget package Web.Config transform

I've created an ASP.NET 5 Class Library using the new project structure provided by Microsoft. 我已经使用Microsoft提供的新项目结构创建了ASP.NET 5类库。 I can build the project and host it on a personal Nuget Feed just fine. 我可以构建该项目并将其托管在个人的Nuget Feed上。 The only problem is, I would like for this package to insert a key into the destination project Web.config file, and it is not cooperating. 唯一的问题是,我希望此软件包将密钥插入目标项目的Web.config文件中,但它不配合使用。

Building the project results in two files: 构建项目将生成两个文件:

../artifacts/bin/{Project}/Debug/{Project}.nupkg ../artifacts/bin/{Project}/Debug/{Project}.symbols.nupkg ../artifacts/bin/{Project}/Debug/{Project}.nupkg ../artifacts/bin/{Project}/Debug/{Project}.symbols.nupkg

{Project}.nupkg is what I am publishing to the hosted Nuget feed. {Project} .nupkg是我要发布到托管的Nuget提要的文件。

I've followed the Nuget docs on how to do this to no avail. 我一直在跟踪Nuget文档 ,但无济于事。

My web.config.transform file looks like this: 我的web.config.transform文件如下所示:

<configuration>
  <appSettings>
    <add key="Test Key" value="Test Value" />
  </appSettings>
</configuration>

When installed in a project, the web.config file remains unchanged. 当安装在项目中时,web.config文件保持不变。

The project structure of the ASP.NET 5 class library doesn't align exactly with the Nuget specs (eg it does not have content , lib , or build directories). ASP.NET 5类库的项目结构与Nuget规范不完全一致(例如,它没有contentlibbuild目录)。 Could that be what is causing the issue? 这可能是导致问题的原因吗?

EDIT I'd like to use this Nuget package in an older (.Net 4.5) project. 编辑我想在一个较旧的(.Net 4.5)项目中使用此Nuget程序包。 Given that ASP.NET 5 is still pretty new, I don't yet have any projects that would make use of its new structure yet (Ie project.json). 鉴于ASP.NET 5仍然很新,我还没有任何项目可以利用其新结构(即project.json)。 That being said, I would like to make the package backwards compatible with older (pre ASP.NET 5 projects) and newer ones (that leverage the JSON file structure) if possible. 话虽这么说,我想尽可能使程序包与较旧的(ASP.NET 5之前的项目)和较新的(利用JSON文件结构)向后兼容。

Unfortunately, NuGet transforms are not supported in ASP.NET 5. If you give more details about your scenario, we might be able to see if there is an alternative. 不幸的是,ASP.NET 5不支持NuGet转换。如果您提供有关方案的更多详细信息,我们也许可以查看是否有替代方法。

Also, you should avoid using web.config. 另外,您应该避免使用web.config。 The new configuration system based on JSON files. 基于JSON文件的新配置系统。 (xml is still supported, though) (尽管仍然支持xml)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM