如何在 .csproj 文件中包含 DLL?
好吧,问题是我没有安装 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 文件?
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.
The problem is that I don't know how to include .dll files. Here is my current code for my .csproj file:
<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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将需要一个 ItemGroup,其中包含名为 Reference 的项目,如下所示:
如果您引用非 GAC'd dll,则需要放入 HintPath(请参阅 mvc mini profiler,这应该与您的构建文件位置相关),或者您需要将 MSBuild 的路径传递到其 ReferencePath 属性中。
You will need an ItemGroup with items called Reference like so:
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.
您可以按如下方式简化 .csproj 中的引用:
通配符也应该有效:
来源: https://github.com/dotnet/sdk/issues/24816#issuecomment-1117948140
You can simplify the reference in the .csproj as follows:
Wildcards should also work:
Source: https://github.com/dotnet/sdk/issues/24816#issuecomment-1117948140