2014-12-18 5 views
0

지금 방금 환경 변수를 설정하고 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 
} 

의 전체하지만이

+0

여기도 같은 기능입니까? http://stackoverflow.com/questions/27448560/creating-a-function-that-writes-to-a-file-in-powershell –

+0

예, 코드 전체를 게시 할 수 있다면 도움이 될 경우 – Macauley

+0

예 확실히 그것이 진화 된 모습을 볼 수 있습니다. 또한'$ env : TEMP'가 가리키는 것을 게시하십시오. 보통은 임시 폴더 일뿐입니다. 또한 오류 메시지를 게시하십시오. –

답변

2

좋아 PowerShell에서 코딩 내 처음이다 그래서 이것에 대한 크레딧은 Micky Balladelli에게 많은 도움을주었습니다! 그는

$env:temp+"\"+"$id-$version.xml" 

을 제안했지만 작동하지 않았습니다. 작품은 비록 변수 내에서, 그래서 미키는 무엇을 제안 보유하는 변수를 한 것으로 무엇을 배치했다 않았다

$OutputFile = $env:temp+"\"+"$id-$version.xml" 

과 코드의 맨 아래에 나는 기능

CreateNewNuspec > $OutputFile 

라고하고는 해결 전적으로 발행

+0

다행 당신이 그것을 해결 :) –

관련 문제