为需要dll的MONO构建csproj

时间:2014-08-20 02:38:11

标签: dll msbuild mono csproj xbuild

我从一个名为Zetcode的网站获得了一行代码,并在此构建第一个示例,我编译代码如下:

gmcs -r:System.Windows.Forms.dll -r:System.Drawing.dll 01-simple-cs-example.cs -out:simple-sample.exe

这构建了绘制窗口的exe,但我不认为我的csproj文件是正确的。

<Project DefaultTargest="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <!-- This Property will make a variable named MSBuildSample, then you can use it to 
            assign to whatever in the script.
            Properties are variables inside the script.
        -->
        <SrcPath>src\</SrcPath>
        <AssemblyName>01-simple-cs-example</AssemblyName>
        <OutputPath>bin\</OutputPath>
    </PropertyGroup>

    <ItemGroup>
        <!-- This Compile statement, gathers all the source files listed in an item called Compiled 
            ItemGroups interact with the source code.
        -->
        <Compile Include="$(SrcPath)01-simple-cs-example.cs" />
    </ItemGroup>
    <!-- In the Build target, the Inputs and Outputs targets which looks to see if the files have been updated,
        or if the files are existent. If the files have not been changed, then the Build target is skipped. 
    -->
    <Target Name="Build" Inputs="@(Compile)" Outputs="$(OutputPath)$(AssemblyName).exe" >
        <!-- The MakeDir directive will create the directory in the property group above, if it meets the 
            condition stated in the Condition= statement. 
        -->
        <Message Text="Creating the output path $(OutputPath)." />
        <MakeDir Directories="$(OutputPath)" Condition="!Exists('$(OutputPath)')" />
        <!-- This Csc is the .NET C# compiler, which then uses the ItemGroup of collected sources called, Compile 
        -->
        <Message Text="Compiling the source code." />
        <Csc Sources="@(Compile)" OutputAssembly="$(OutputPath)$(AssemblyName).exe" />
    </Target>



</Project>

这是尝试运行xbuild和msbuild的结果。

C:\Users\User01\Dropbox\programming\csharp\zetcode-csharp-winforms\01-simple-cs-example>xbuild
XBuild Engine Version 3.3.0.0
Mono, Version 3.3.0.0
Copyright (C) Marek Sieradzki 2005-2008, Novell 2008-2011.

Build started 7/25/2014 2:47:41 PM.
__________________________________________________
Project "C:\Users\User01\Dropbox\programming\csharp\zetcode-csharp-winforms\01-simple-cs-example\01-simple-cs-example.csproj" (default target(s)):
        Target Build:
                Created directory "bin\"
                Tool C:\mono\Mono-3.2.3\bin\gmcs.bat execution started with arguments:  /out:bin\01-simple-cs-example.exe src\01-simple-cs-example.cs
src\01-simple-cs-example.cs(1,22): error CS0234: The type or namespace name `Forms' does not exist in the namespace `System.Windows'. Are you missing `System.Windows.Forms' assembly reference?
src\01-simple-cs-example.cs(2,14): error CS0234: The type or namespace name `Drawing' does not exist in the namespace `System'. Are you missing `System.Drawing' assembly reference?
src\01-simple-cs-example.cs(4,23): error CS0246: The type or namespace name `Form' could not be found. Are you missing an assembly reference?
        Task "Csc" execution -- FAILED
        Done building target "Build" in project "C:\Users\User01\Dropbox\programming\csharp\zetcode-csharp-winforms\01-simple-cs-example\01-simple-cs-example.csproj".-- FAILED
Done building project "C:\Users\User01\Dropbox\programming\csharp\zetcode-csharp-winforms\01-simple-cs-example\01-simple-cs-example.csproj".-- FAILED

Build FAILED.
Errors:

C:\Users\User01\Dropbox\programming\csharp\zetcode-csharp-winforms\01-simple-cs-example\01-simple-cs-example.csproj (default targets) ->
(Build target) ->

        src\01-simple-cs-example.cs(1,22): error CS0234: The type or namespace name `Forms' does not exist in the namespace `System.Windows'. Are you missing `System.Windows.Forms' assembly reference?
        src\01-simple-cs-example.cs(2,14): error CS0234: The type or namespace name `Drawing' does not exist in the namespace `System'. Are you missing `System.Drawing' assembly reference?
        src\01-simple-cs-example.cs(4,23): error CS0246: The type or namespace name `Form' could not be found. Are you missing an assembly reference?

         0 Warning(s)
         3 Error(s)

Time Elapsed 00:00:01.5341534

这是MSBuild运行的结果。 MSBuild成功完成,但我想这是因为MSBuild知道在哪里查看,而不必在csproj文件中指定它。

C:\Users\User01\Dropbox\programming\csharp\zetcode-csharp-winforms\01-simple-cs-example>MSBuild
Microsoft (R) Build Engine version 4.0.30319.18408
[Microsoft .NET Framework, version 4.0.30319.18444]
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 7/25/2014 2:48:04 PM.
Project "C:\Users\User01\Dropbox\programming\csharp\zetcode-csharp-winforms\01-simple-cs-example\01-simple-cs-example.csproj" on node 1 (default targets).
Build:
  C:\Windows\Microsoft.NET\Framework\v2.0.50727\Csc.exe /out:bin\01-simple-cs-example.exe src\01-simple-cs-example.cs
Done Building Project "C:\Users\User01\Dropbox\programming\csharp\zetcode-csharp-winforms\01-simple-cs-example\01-simple-cs-example.csproj" (default targets).


Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:04.36

我不知道要放入csproj文件的内容,以使其加载我在命令行中使用的gmcs进行编译的DLL。有线索吗?

-- EDIT 2014-08-20 --

使用knocte的答案后,我能够看到如何在References文件中添加csproj。它就像添加一个项目组一样简单,并在C#源文件中添加了using列出的参考文献。

  <ItemGroup>
    <Reference Include="System.Windows.Forms" />
    <Reference Include="System.Drawing" />
    <Reference Include="System" />
  </ItemGroup>

如果您手动构建csproj文件,这是手动执行此操作的方法。

1 个答案:

答案 0 :(得分:0)

只需使用IDE(MonoDevelop或Visual Studio)向System.Windows.FormsSystem.Drawing库添加GAC引用。