简体   繁体   English

如何在我的 .csproj 文件中包含 DLL?

[英]How do I include DLLs in my .csproj file?

Well, the thing is that I don't have Visual Studio installed and I don't want to install it, so, I made a batch file that compiles my .csproj file and all of my source files too.好吧,问题是我没有安装 Visual Studio 并且我不想安装它,所以,我制作了一个批处理文件来编译我的 .csproj 文件和我的所有源文件。

The problem is that I don't know how to include .dll files.问题是我不知道如何包含 .dll 文件。 Here is my current code for my .csproj file:这是我的 .csproj 文件的当前代码:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <AssemblyName>Project</AssemblyName>
    <OutputPath>Bin\</OutputPath>
  </PropertyGroup>

  <ItemGroup>
        <!-- .cs files -->
    <Compile Include="program.cs" />
  </ItemGroup>

  <Target Name="Build">
    <MakeDir Directories="$(OutputPath)"      Condition="!Exists('$(OutputPath)')" />
    <Csc Sources="@(Compile)" OutputAssembly="$(OutputPath)$(AssemblyName).exe" />
  </Target>
</Project>

What do I need to change to include / reference a dll file into the compilation process?我需要更改什么才能在编译过程中包含/引用 dll 文件?

You will need an ItemGroup with items called Reference like so:您将需要一个包含名为 Reference 的项目的 ItemGroup,如下所示:

<ItemGroup>
    <Reference Include="Microsoft.Practices.Unity" />
    <Reference Include="MvcMiniProfiler">
      <HintPath>..\packages\MiniProfiler.1.6\lib\MvcMiniProfiler.dll</HintPath>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.configuration" />
    <Reference Include="System.Core" />
    <Reference Include="System.Data.Entity" />
    <Reference Include="System.Runtime.Serialization" />
    <Reference Include="System.Security" />
    <Reference Include="System.Web" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>

If you are referencing non-GAC'd dlls, you will need to either put in the HintPath (see mvc mini profiler, this should be relative to your build files location), or you will need to pass the path to MSBuild in its ReferencePath property.如果您要引用非 GAC 的 dll,则需要放入 HintPath(请参阅 mvc mini profiler,这应该与您的构建文件位置相关),或者您需要在其 ReferencePath 中将路径传递给 MSBuild财产。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM