Visual Studio에서 컴파일 할 때 msbuild 대신 devenv를 사용하고 있습니다. devenv가 msbuild를 호출하는 방법을 확인하는 것은 좋을 것입니다 (그러나 VS가 아닌 오픈 소스 도구 인 경우, 우리는 할 수 없습니다). 그래서, 나는 그것을 할 수 있다고 생각하지 않습니다. 어쩌면 당신이하려는 일을하는 또 다른 접근법이있을 수 있습니다.
MSbuild v3.5는 MSbuild 4.0과 같이 동적 작업 생성을 지원하지 않지만 create customized tasks 및 import them 일 수 있습니다.
먼저, 간단한 클래스 라이브러리를 만들 (nuget.targets에서 촬영) nuget.exe 다운로드 작업을 포함하는 (나는 DownloadNuget2008.dll라고 불렀다) :
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;
}
}
}
}
나는 내 NuGet 패키지를 복원하는 데 사용을 아래 Exec에서 작업에 비주얼 스튜디오 2008 (당신의 csproj/vbproj 편집) :
<UsingTask AssemblyFile="$(SolutionDir)DownloadNuget2008.dll" TaskName="DownloadNuget2008Task" />
<!-- Download NuGet.exe if it does not already exist -->
<PropertyGroup>
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(SolutionDir)nuget.exe</NuGetExePath>
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">true</DownloadNuGetExe>
</PropertyGroup>
<Target Name="_DownloadNuGet">
<Message Text="Downloading nuget..." />
<DownloadNuget2008Task OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
<Message Text="Downloading nuget - done." />
</Target>
<!-- NuGet Packages Installation (Begin) -->
<Target Name="Install-Packages">
<Exec Command="$(SolutionDir)nuget install $(ProjectDir)packages.config -o $(SolutionDir)packages" />
</Target>
<!-- NuGet Packages Installation (End) -->
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="BeforeBuild">
<CallTarget Targets="_DownloadNuGet" />
<CallTarget Targets="Install-Packages" />
</Target>
는 그런 다음 출력이 표시됩니다
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".
VS2012와 VS2008 모두에 동일한 .targets 파일을 사용하고 싶지만 MSBuild 3.5와 4.0에는 많은 차이점이 있으므로 구체적인 접근 방법이 더 쉽습니다.
.targets 파일에서 nuget.exe를 자동으로 다운로드한다는 사실이 아니라면 작동합니다. 그것에 대해 어떤 제안이 있습니까? 이 질문을 적절히 반영하도록 질문을 수정하겠습니다. – julealgon
나는 그것에 대해 생각하고 나의 대답을 업데이트 할 것이다. –
이제 충분히 적합하다고 생각합니다. 나는 커스텀 태스크를 만드는 방법, 굉장한 것을 보지 못했다. 이 작업을 위해 새 프로젝트를 만들어야하는 것은 다소 번거롭지만 실제로 MSBuild 3.5를 사용하는 다른 방법은 없다고 생각됩니다. 또한 toolsversion이나 .targets 파일의 일부를 기반으로 일부 스위치를 만들어 두 스위치를 하나로 병합 할 수 있습니까? 나는 이것이 우리 상황에서 이상적이라고 생각한다. 나는 며칠 동안 그것을 테스트 할 수 없지만 답변으로 귀하의 게시물을 표시합니다. 도움을 많이 주셔서 감사합니다. – julealgon