现在我刚刚设置了我的环境变量,并尝试将文件输出到Temp目录。每次我运行批处理文件,虽然它说拒绝访问途径,下面是我的全部代码
Param(
[Parameter(Mandatory=$true,
ValueFromRemainingArguments=$true,
HelpMessage="List of files to add to the package")]
[String] $File
)
Function CreateNugetPackage {
Param(
[String] $File
)
Process {
$retCode = 0
write-verbose "Getting ID, Version, and Filepath of $file..."
$version = (Get-Item $File).VersionInfo.FileVersion
$id = $file.Substring(0, $File.LastIndexof('.'))
$filepath = Get-ChildItem "$File"
$netVer = ildasm /text $File| findstr Metadata
$netVerShort = $netVer.Substring(0, $netVer.IndexOf('.') + 1 + $netVer.Substring($netVer.IndexOf('.') + 1).IndexOf('.'))
$netVerConv = @{
'v2.0' = "lib\net20";
'// Metadata version: v2.0' = "lib\net20";
'v3.0' = "lib\net30";
'v3.5' = "lib\net35";
'v4.0' = "lib\net40";
'v4.5' = "lib\net45";
}
$target = $netVerConv.Get_Item($netVerShort)
$OriginalFilename = (Get-Item $File).VersionInfo.OriginalFilename
write-verbose "$id"
write-verbose "$version"
write-verbose "$filepath"
write-verbose "$netVer"
write-verbose "$netVerShort"
write-verbose "$target"
function CreateNewNuspec {
param ($File)
$x=
"<?xml version=""1.0""?>
<package xmlns=""http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"">
<metadata>
<id>$id</id>
<version>$version</version>
<authors>CME</authors>
<owners>CME</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$filepath</description>
</metadata>
<files>
<file src=""$id.dll"" target=""$target""/>
</files>
</package>"
return $x
}
CreateNewNuspec > $env:temp "$id-$version.xml"
Return $retCode
}
}
$retVal = CreateNugetPackage $File
exit $retVal
}
这不是最干净的代码,但这是我第一次在powershell编码
答案 0 :(得分:2)
好的,所以对Micky Balladelli非常感谢他的帮助!他建议
$env:temp+"\"+"$id-$version.xml"
但这不起作用。虽然工作在一个变量中,但是我做了一个变量来控制Micky建议的内容
$OutputFile = $env:temp+"\"+"$id-$version.xml"
在代码的底部我调用了函数
CreateNewNuspec > $OutputFile
并完全解决了这个问题