简体   繁体   English

在install.ps1 nuget脚本中获取所有项目“种类”

[英]Getting all project “kinds” in a install.ps1 nuget script

I'm trying to code something in an install.ps1 post-install script for a Nuget package that depends on the project type. 我正在尝试根据项目类型在Nuget软件包的install.ps1安装后脚本中编写一些代码。 If it's a web project type, I want to do something different after install. 如果是Web项目类型,安装后我想做些不同的事情。 So I'm looking at the $project.Kind to determine this. 因此,我正在查看$ project.Kind确定这一点。 The problem is that when I test with a WebApi project, this always returns the wrong project kind. 问题是,当我用WebApi项目进行测试时,这总是返回错误的项目类型。 If you look in a newly created C# WebApi project, it has two project types listed in the element (one for Web Application and one for general C#). 如果您查看一个新创建的C#WebApi项目,则该元素在元素中列出了两种项目类型(一种用于Web应用程序,一种用于常规C#)。 The $project.Kind property is returning the C# identifier...I need to see if it's a web application, so I need the first one as well. $ project.Kind属性返回C#标识符...我需要查看它是否是Web应用程序,因此也需要第一个。 I can't find the proper call to get the list of all project types from $project: 我找不到从$ project获取所有项目类型的列表的正确调用:

param($installPath, $toolsPath, $package, $project)

if($project.Kind -eq {guid goes here}){do my custom thing here...}

I've looked through the available accessors on the EnvDte Project object and can't find anything that looks promising. 我已经浏览了EnvDte Project对象上的可用访问器,但找不到任何有前途的东西。

https://msdn.microsoft.com/en-us/library/envdte.project.aspx https://msdn.microsoft.com/en-us/library/envdte.project.aspx

Any ideas? 有任何想法吗?

The solution I used was as Brad suggested...just took the low road and looked for a web config like such: 我使用的解决方案是Brad建议的...只是走了一条小路,然后寻找了这样的Web配置:

$webItem = $null;

try{
    $webItem = $project.ProjectItems.Item("Web.config")
}
catch
{
}

if($webItem -eq $null)
{
  --processing for non-web project.
}

Not very elegant, but it appears to work for my simple cases. 不太优雅,但似乎可以用于我的简单案例。

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

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