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

22

实际上我没有安装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文件包含/引用到编译过程中?

1个回答

29
你需要一个名为 "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>
如果你正在引用未加入全局程序集缓存(GAC)的dll文件,你需要在HintPath中指定路径(参考mvc mini profiler中的写法,路径应该相对于构建文件的位置),或者在MSBuild的ReferencePath属性中传递该路径。

这似乎适用于旧的csproj约定。在新的“SDK样式”csproj文件中如何做到这一点? - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接