如何在.csproj文件中包含dll ?

本文关键字:包含 dll 文件 csproj | 更新日期: 2023-09-27 18:11:37

问题是我没有安装Visual Studio,我也不想安装它,所以,我做了一个批处理文件来编译我的。csproj文件和所有的源文件。

问题是我不知道如何包含。dll文件。下面是我的。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>

为了在编译过程中包含/引用dll文件,我需要做什么更改?

如何在.csproj文件中包含dll ?

您将需要一个ItemGroup,其中包含名为Reference的项,如下所示:

<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>

如果你引用的是非gac dll,你需要输入HintPath(参见mvc mini profiler,这应该与你的构建文件位置相关),或者你需要将路径传递给MSBuild的ReferencePath属性。