2016-01-15 20 views
0

我有這個下面的類,我試圖讓一個DLL從如何創建一個引用c#asp.net中其他dll的類的dll?

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using NRules.Fluent.Dsl; 
using NRule.site.Model; 
using NRule.site.Utilities; 

namespace NRule.site.Rules 
{ 
    public class AllowAtleastOneCountryRule : Rule 
    { 
     public override void Define() 
     { 
      FundProfile productProfile = null; 
      string str = RuleTexts.AllowAtleastOneCountryRule; 
      bool enabled = AllRules.GetDict()[str]; 

      When() 
       .Match<FundProfile>(() => productProfile) 
       .Exists<FundProfile>(p => enabled, p => RuleViolation(p)); 

      Then() 
       .Do(_ => productProfile.DisplayError(str)); 
     } 

     bool RuleViolation(FundProfile pp) 
     { 
      if (pp.CountriesListP.Count==0) 
       return true; 
      if (pp.CountriesListP.Any(c => c.Allowed)) 
       return false; 
      else 
       return true; 

     } 
    } 
} 

正如你可以看到它具有外部參考

using NRules.Fluent.Dsl; 

和其他一些類,均達到層次結構中的

using NRule.site.Model; 
using NRule.site.Utilities; 

當我嘗試CSC命令我得到這個

csc /target:library /out:Mylib.dll AllowAtLeastOneCountryRule.cs 
Microsoft (R) Visual C# Compiler version 4.0.30319.34209 
for Microsoft (R) .NET Framework 4.5 
Copyright (C) Microsoft Corporation. All rights reserved. 

AllowAtleastOneCountryRule.cs(5,7): error CS0246: The type or namespace name 
     'NRules' could not be found (are you missing a using directive or an 
     assembly reference?) 
AllowAtleastOneCountryRule.cs(6,18): error CS0234: The type or namespace name 
     'Model' does not exist in the namespace 'NRule.site' (are you missing a 
     assembly reference?) 
AllowAtleastOneCountryRule.cs(7,18): error CS0234: The type or namespace name 
     'Utilities' does not exist in the namespace 'NRule.site' (are you 
     missing an assembly reference?) 
AllowAtleastOneCountryRule.cs(11,47): error CS0246: The type or namespace name 
     'Rule' could not be found (are you missing a using directive or an 
     assembly reference?) 
AllowAtleastOneCountryRule.cs(27,28): error CS0246: The type or namespace name 
     'FundProfile' could not be found (are you missing a using directive or 
     an assembly reference?) 

如何引用所有程序集並將此類編譯爲DLL? 任何指導都會很棒。

回答

0

你應該在你的代碼中引用命令中指定的附加程序集。

csc /target:library reference:assembly_contained_your_types.dll /out:Mylib.dll AllowAtLeastOneCountryRule.cs 
+0

我可以添加對這個Fluent.dsl程序集的引用,因爲它是一個dll。但是,我怎樣才能參考其他模型和實用程序?它們不是程序集,而是層次結構上的一個文件夾中的其他類。那些文件包含其他參考。 – talaa123

+0

'它們不是程序集,而是層次結構上一個文件夾中的其他類.'如果它們在另一個'cs'文件中,則應該編譯它們。按空格分開列出它們。 –

+0

但在這些文件中還有其他文件被引用。我的意思是可能有50個文件在某些​​方面互相連接。我應該如何將它們全部編譯在一起?我可以做些什麼,如從項目中刪除此文件「AllowAtLeastOneCountryRule.cs」,並編譯項目的其餘部分。從bin文件夾中獲取該項目的dll,在該文件中引用它,然後僅參考「FluentDsl.dll」和「myproject.dll」嘗試「csc」。這看起來對你來說可行嗎? – talaa123