2012-07-29 21 views
12
में NuGet पैकेज फ़ोल्डर जाओ

मैं NUnit की तरह निष्पादन उपकरण जो मैं MSBuild में NuGet के माध्यम से प्रबंधन कॉल करना चाहते हैं:MSBuild

<Target Name="Test"> 
    <CreateItem Include="$(BuildCompileDirectory)\*.Tests.*dll"> 
    <Output TaskParameter="Include" ItemName="TestAssemblies" /> 
    </CreateItem> 
    <NUnit 
    Assemblies="@(TestAssemblies)" 
    ToolPath="$(PackagesDirectory)\NUnit.2.5.10.11092\tools" 
    WorkingDirectory="$(BuildCompileDirectory)" 
    OutputXmlFile="$(BuildDirectory)\$(SolutionName).Tests.xml" /> 
</Target> 

समस्या यह है कि एक NuGet संकुल की फ़ोल्डर पैकेज की संस्करण संख्या युक्त है । उदाहरण के लिए nunit-console.exe फ़ोल्डर packages\NUnit.2.5.10.11092\tools में है। यदि मैं NUnit पैकेज को अद्यतन करता हूं तो यह पथ बदल जाएगा और मुझे अपनी MSBuild स्क्रिप्ट को अपडेट करना होगा। यह स्वीकार्य नहीं है।

MSBuild निर्देशिका में वाइल्डकार्ड की अनुमति नहीं है, तो यह काम नहीं कर रहा:

ToolPath="$(PackagesDirectory)\NUnit.*\tools" 

कैसे मैं अपने निर्माण स्क्रिप्ट अद्यतन करने के लिए जब भी मैं एक NuGet पैकेज को अद्यतन बिना MSBuild में उपकरण कॉल कर सकते हैं?

उत्तर

12

आप MSBuild Transforms उपयोग कर सकते हैं एक विशिष्ट उपकरण के रिश्तेदार निर्देशिका पाने के लिए:

<ItemGroup> 
    <NunitPackage Include="$(PackagesDirectory)\NUnit.*\tools\nunit-console.exe"/> 
</ItemGroup> 

<Target Name="Test"> 
    <CreateItem Include="$(BuildCompileDirectory)\*.Tests.*dll"> 
    <Output TaskParameter="Include" ItemName="TestAssemblies" /> 
    </CreateItem> 
    <NUnit 
    Assemblies="@(TestAssemblies)" 
    ToolPath="@(NunitPackage->'%(relativedir)')" 
    WorkingDirectory="$(BuildCompileDirectory)" 
    OutputXmlFile="$(BuildDirectory)\$(SolutionName).Tests.xml" /> 
</Target> 
+1

"$ (PackagesDirectory)" है एक आइटम आप अपने आप को परिभाषित किया है? –

+0

@ डेविड टचपैक हां, यह है। –

+0

क्या होगा यदि समाधान बड़ा है और उसी पैकेज के कई संस्करण हैं (विभिन्न परियोजनाओं द्वारा उपयोग किया जाता है)? उस स्थिति में आप गलत संस्करण का संदर्भ दे सकते हैं (यानी वह नहीं जो आपके प्रोजेक्ट की "packages.config" फ़ाइल में निर्दिष्ट है। – johnnyjob

 संबंधित मुद्दे