прямо сейчас Я только что установил переменную окружения и пытаюсь получить файл в каталоге Temp. Каждый раз, когда я запустить командный файл, хотя он говорит, что доступ к пути запрещен, ниже полнота моего кодаДоступ к пути отрицается Powershell
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
Эта функция используется здесь? http://stackoverflow.com/questions/27448560/creating-a-function-that-writes-to-a-file-in-powershell –
Да, если это поможет, я могу опубликовать весь код – Macauley
да определенно, чтобы мы могли увидеть, как оно развилось. Также укажите, на что указывает '$ env: TEMP', обычно это только ваша временная папка. Также опубликуйте сообщение об ошибке. –