我想了解使用Microsoft Build Engine(也稱爲MSBuild)構建C#項目的過程,以及我面臨的問題。問題很簡單,認爲我只是不明白某件事情。無法在'系統'中找到類型或命名空間名稱'linq'
我寫了一個由2個.cs文件組成的簡單程序。 第一個文件是「MathOp.cs」。在這個文件中我定義了2個函數:add(double num1,double num2)和multiply(doble,double); 第二個文件是「Program.cs」。在這裏我定義了兩個變量,我通過添加函數放置在MathOp文件中並獲取rezult; 這個程序是正確的。
然後我寫了一個簡單的msbuild文件,我定義了構建任務和目標。 當我在Visual Studio命令提示符下啓動它時,我得到了erorr cs0234:在System命名空間中找不到類型或命名空間名稱Linq。最有趣的是我引用了ms.dll文件中的System.dll等。如果我在Program.cs文件中評論使用指令,這個錯誤消失。
<Project DefaultTargets="Compile"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >
<PropertyGroup>
<AssemblyInfo>Build</AssemblyInfo>
<builtdir>Build\</builtdir>
</PropertyGroup>
<ItemGroup>
<CSFile Include="msbuildTest\Program.cs"/>
<CSFile Include="msbuildTest\Properties\AssemblyInfo.cs"/>
<CSFile Include="msbuildTest\MathOp.cs"/>
<Reference Include="System.dll"/>
<Reference Include="System.Data.dll"/>
<Reference Include="System.Drawing.dll"/>
<Reference Include="System.Windows.Forms.dll"/>
<Reference Include="System.XML.dll"/>
</ItemGroup>
<Target Name="PreBuild">
<Exec Command="if not exist $(builtdir) md $(builtdir)"/>
</Target>
<Target Name="Compile" DependsOnTargets="PreBuild">
<Csc Sources="@(CSFile)"
References="@(Reference)"
OutputAssembly="$(builtdir)$(MSBuildProjectName).exe"
TargetType="exe"/>
</Target>
<Target Name="Clean" >
<Exec Command="DEL $(builtdir)$(AssemblyInfo).exe"/>
</Target>
<Target Name="Rebuild" DependsOnTargets="Clean;Compile"/>
你參考什麼版本的mscorlib.dll的? – DaveShaw
您還需要參考'System.Core.dll' –
是的,我包含system.core.dll但問題是鋼鐵是。 – Tequila