Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 2012 从内联任务访问NuGet时出错_Visual Studio 2012_Msbuild_Nuget - Fatal编程技术网

Visual studio 2012 从内联任务访问NuGet时出错

Visual studio 2012 从内联任务访问NuGet时出错,visual-studio-2012,msbuild,nuget,Visual Studio 2012,Msbuild,Nuget,在VisualStudio2012中,我创建了一个有效的MsBuild内联任务,直到取消注释一行代码。未注释时,将失败,并显示以下消息: C:\Build\MyScript.targets(49,5): error MSB4018: The "MyCustomGetPath" task failed unexpectedly. C:\Build\MyScript.targets(49,5): error MSB4018: System.IO.FileNotFoundExcep

在VisualStudio2012中,我创建了一个有效的MsBuild内联任务,直到取消注释一行代码。未注释时,将失败,并显示以下消息:

C:\Build\MyScript.targets(49,5): error MSB4018: The "MyCustomGetPath" task failed unexpectedly.
C:\Build\MyScript.targets(49,5): error MSB4018: System.IO.FileNotFoundException: Could not load file or assembly 'NuGet, Version=2.7.40906.75, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
C:\Build\MyScript.targets(49,5): error MSB4018: File name: 'NuGet, Version=2.7.40906.75, Culture=neutral, PublicKeyToken=null'
C:\Build\MyScript.targets(49,5): error MSB4018:    at InlineCode.GetNuGetRepositoryPath.Execute()
C:\Build\MyScript.targets(49,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
C:\Build\MyScript.targets(49,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext()
C:\Build\MyScript.targets(49,5): error MSB4018: 
C:\Build\MyScript.targets(49,5): error MSB4018: === Pre-bind state information ===
C:\Build\MyScript.targets(49,5): error MSB4018: LOG: User = Biz\baria2
C:\Build\MyScript.targets(49,5): error MSB4018: LOG: DisplayName = NuGet, Version=2.7.40906.75, Culture=neutral, PublicKeyToken=null
C:\Build\MyScript.targets(49,5): error MSB4018:  (Fully-specified)
C:\Build\MyScript.targets(49,5): error MSB4018: LOG: Appbase = file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/
C:\Build\MyScript.targets(49,5): error MSB4018: LOG: Initial PrivatePath = NULL
C:\Build\MyScript.targets(49,5): error MSB4018: Calling assembly : (Unknown).
C:\Build\MyScript.targets(49,5): error MSB4018: ===
C:\Build\MyScript.targets(49,5): error MSB4018: LOG: This bind starts in default load context.
C:\Build\MyScript.targets(49,5): error MSB4018: LOG: Using application configuration file: C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe.Config
C:\Build\MyScript.targets(49,5): error MSB4018: LOG: Using host configuration file: 
C:\Build\MyScript.targets(49,5): error MSB4018: LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
C:\Build\MyScript.targets(49,5): error MSB4018: LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
C:\Build\MyScript.targets(49,5): error MSB4018: LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/NuGet.DLL.
C:\Build\MyScript.targets(49,5): error MSB4018: LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/NuGet/NuGet.DLL.
C:\Build\MyScript.targets(49,5): error MSB4018: LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/NuGet.EXE.
C:\Build\MyScript.targets(49,5): error MSB4018: LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/NuGet/NuGet.EXE.
C:\Build\MyScript.targets(49,5): error MSB4018: 
Done Building Project "C:\Build\MyScript.targets" (default targets) -- FAILED.
以下是内联任务:

<UsingTask TaskName="MyCustomGetPath" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
  <ParameterGroup>
    <config ParameterType="System.String" Required="true" />
    <repositoryPath ParameterType="System.String" Output="true" />
  </ParameterGroup>
  <Task>
    <Reference Include="$(NuGetExePath)" />
    <Using Namespace="NuGet" />
    <Using Namespace="System.IO" />
    <Code Type="Fragment" Language="cs">
      <![CDATA[
          ISettings settings = null;
          string directoryName = Path.GetDirectoryName(Path.GetFullPath(config));
          string fileName = null;
          if (File.Exists(config))
          {
              fileName = Path.GetFileName(config);
          }
          
          //var temp = new NullLogger();
          //MessageLevel msg = MessageLevel.Warning;
          //PhysicalFileSystem physicalFileSystem = new PhysicalFileSystem(directoryName);

          repositoryPath = directoryName;
          ]]>
    </Code>
  </Task>
</UsingTask>



是的,此代码引用的是NuGet.exe(本例中为2.7版)。上面有三行注释;取消其中任何一个的注释都会导致错误。总的来说,我怀疑这是错误的。这是有道理的,但我有什么办法来解决这个问题呢

更新
.

我在控制台csproj中尝试了这段代码,如果我将Nuget引用添加到Nuget.exe 2.0.0中,它将加载并编译良好,但在编译本身中加载Nuget.exe 2.7.0失败。因此,我假设Nuget.exe在作为程序集加载时遇到一些问题,或者需要一些依赖项。你能用Nuget.exe 2.0.0试试看它是否适合你吗?在我的试用过程中,三个注释的行,我一直在注释自己,因为我没有从
PhysicalFileSystem
类的何处开始,甚至
ISettings
也不例外。可能重复
<UsingTask TaskName="MyCustomGetPath" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
  <ParameterGroup>
    <config ParameterType="System.String" Required="true" />
    <repositoryPath ParameterType="System.String" Output="true" />
  </ParameterGroup>
  <Task>
    <Reference Include="$(NuGetExePath)" />
    <Using Namespace="NuGet" />
    <Using Namespace="System.IO" />
    <Code Type="Fragment" Language="cs">
      <![CDATA[
          ISettings settings = null;
          string directoryName = Path.GetDirectoryName(Path.GetFullPath(config));
          string fileName = null;
          if (File.Exists(config))
          {
              fileName = Path.GetFileName(config);
          }
          
          //var temp = new NullLogger();
          //MessageLevel msg = MessageLevel.Warning;
          //PhysicalFileSystem physicalFileSystem = new PhysicalFileSystem(directoryName);

          repositoryPath = directoryName;
          ]]>
    </Code>
  </Task>
</UsingTask>