Постройте csproj для MONO, который требует dll

У меня есть строка кода, которую я получил с сайта под названием Zetcode, и в этом, чтобы построить первый пример, я скомпилировал код следующим образом:

gmcs -r:System.Windows.Forms.dll -r:System.Drawing.dll 01-simple-cs-example.cs -out:simple-sample.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 файл, чтобы он загружал те DLL, которые я использовал в командной строке для компиляции с помощью gmcs, Есть какие-нибудь подсказки?

- РЕДАКТИРОВАТЬ 2014-08-20 -

Воспользовавшись ответом от knocte, я смог увидеть, как References добавляются в csproj файл. Это так же просто, как добавить группу элементов и добавить ссылки, которые вы перечислили с using в исходном файле C#.

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

Это ручной способ сделать это, если вы создаете csproj подать вручную.

1 ответ

Решение

Просто используйте IDE (MonoDevelop или Visual Studio), чтобы добавить GAC-ссылку на System.Windows.Forms а также System.Drawing библиотеки.

Другие вопросы по тегам