Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you compile from Visual Studio you're using devenv instead of msbuild. It would be great to see how devenv calls msbuild (but being VS a non open-source tool, we just can't). So, I don't think it is possible to do that. Maybe there's another approach to do what are you're trying to do.</p> <p>MSbuild v3.5 does not support dynamic task creation as MSbuild 4.0, but you can <a href="http://tech.pro/tutorial/934/creating-msbuild-tasks-in-csharp" rel="nofollow">create customized tasks</a> and <a href="http://msdn.microsoft.com/en-us/library/t41tzex2%28v=vs.90%29.aspx" rel="nofollow">import them</a>.</p> <p>First, create a simple class library (I called it DownloadNuget2008.dll) containing the task to download nuget.exe (taken from nuget.targets):</p> <pre><code>using System; using System.IO; using System.Net; using Microsoft.Build.Utilities; namespace DownloadNuget2008 { public class DownloadNuget2008Task : Task { public string OutputFilename { get; set; } public override bool Execute() { try { OutputFilename = Path.GetFullPath(OutputFilename); Log.LogMessage("Downloading latest version of NuGet.exe..."); var webClient = new WebClient(); webClient.DownloadFile("https://nuget.org/nuget.exe", OutputFilename); return true; } catch (Exception ex) { Log.LogErrorFromException(ex); return false; } } } } </code></pre> <p>I used to restore my NuGet packages on Visual Studio 2008 with the Exec Task below (edit your csproj/vbproj):</p> <pre><code> &lt;UsingTask AssemblyFile="$(SolutionDir)DownloadNuget2008.dll" TaskName="DownloadNuget2008Task" /&gt; &lt;!-- Download NuGet.exe if it does not already exist --&gt; &lt;PropertyGroup&gt; &lt;NuGetExePath Condition=" '$(NuGetExePath)' == '' "&gt;$(SolutionDir)nuget.exe&lt;/NuGetExePath&gt; &lt;DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' "&gt;true&lt;/DownloadNuGetExe&gt; &lt;/PropertyGroup&gt; &lt;Target Name="_DownloadNuGet"&gt; &lt;Message Text="Downloading nuget..." /&gt; &lt;DownloadNuget2008Task OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" /&gt; &lt;Message Text="Downloading nuget - done." /&gt; &lt;/Target&gt; &lt;!-- NuGet Packages Installation (Begin) --&gt; &lt;Target Name="Install-Packages"&gt; &lt;Exec Command="$(SolutionDir)nuget install $(ProjectDir)packages.config -o $(SolutionDir)packages" /&gt; &lt;/Target&gt; &lt;!-- NuGet Packages Installation (End) --&gt; &lt;Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /&gt; &lt;Target Name="BeforeBuild"&gt; &lt;CallTarget Targets="_DownloadNuGet" /&gt; &lt;CallTarget Targets="Install-Packages" /&gt; &lt;/Target&gt; </code></pre> <p>Then you will see on the output:</p> <pre><code>Target BeforeBuild: Task "CallTarget" Target "_CheckForInvalidConfigurationAndPlatform" skipped. Previously built successfully. Target _DownloadNuGet: Task "Message" Downloading nuget... Done executing task "Message". Using "DownloadNuget2008Task" task from assembly "C:\marcos\Testes\NuGet2008\ConsoleApplication1\DownloadNuget2008.dll". Task "DownloadNuget2008Task" Downloading latest version of NuGet.exe... Done executing task "DownloadNuget2008Task". Task "Message" Downloading nuget - done. Done executing task "Message". Done executing task "CallTarget". Task "CallTarget" Target "_CheckForInvalidConfigurationAndPlatform" skipped. Previously built successfully. Target Install-Packages: Task "Exec" Command: C:\marcos\Testes\NuGet2008\ConsoleApplication1\nuget install C:\marcos\Testes\NuGet2008\ConsoleApplication1\ConsoleApplication1\packages.config -o C:\marcos\Testes\NuGet2008\ConsoleApplication1\packages Successfully installed 'elmah 1.2.2'. Done executing task "Exec". Done executing task "CallTarget". </code></pre> <p>I understand you wish to use the same .targets file to both VS2012 and VS2008, but (as you said) there are many differences between MSBuild 3.5 and 4.0 so a specific approach is easier to do.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload