我如何在 VSCode 中移动带有 debug/release 的引用 DLL?
How do i move referenced DLLs with debug/release in VSCode?
设置
我将一个 C# VS2015 控制台应用程序项目转换为 VSCode,我正在尝试添加 DLL 引用并在构建时移动任何引用的 DLL。
开始时,Dotnet add package
没有工作,出现错误 The project does not support adding package references through the add package command.
,所以我手动将项目添加到 .csproj
文件中。我要添加的包是本地版本,位于./Lib/AutoItX
Lib/
└── AutoItX
├── AutoItX3_x64.dll
├── AutoItX3.Assembly.dll
├── AutoItX3.Assembly.xml
└── AutoItX3.dll
对 .csprog
的补充
<ItemGroup>
<Reference Include="AutoItX">
<HintPath>.\Lib\AutoItX\AutoItX3.Assembly.dll</HintPath>
</Reference>
</ItemGroup>
参考有效,如果我手动将 DLL 移动到 Debug 文件夹,它会找到它并且一切正常。
问题
有没有办法自动将 DLL 移动到文件夹中?
目前,在重新 运行 之后,我的调试文件夹如下所示:
bin/
└── x64
└── Debug
├── AutoItX3.Assembly.dll
├── AutoItX3.Assembly.xml
├── Application.exe
├── Application.exe.config
└── Application.pdb
我希望 AutoItX3_x64.dll
自动包含在 x64 构建中,如果可能的话,AutoIt3.dll
包含在 x86 构建中(它目前没有为 x86 构建设置,我只是想知道如何)
附加信息
我的launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "clr",
"request": "launch",
"preLaunchTask": "compile",
"program": "${workspaceFolder}/Application/bin/x64/Debug/StartApplication.exe",
"args": ["./Download/start.json"],
"cwd": "${workspaceFolder}",
"console": "externalTerminal",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "clr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
我的tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "compile",
"type": "shell",
"command": "dotnet",
"args": [
// Ask msbuild to generate full paths for file names.
"msbuild",
"Application.sln",
"/property:GenerateFullPaths=true",
"/property:Platform=x64"
],
"group": "build",
"presentation": {
// Reveal the output only if unrecognized errors occur.
"reveal": "silent"
},
// Use the standard MS compiler pattern to detect errors, warnings and infos
"problemMatcher": "$msCompile"
}
]
}
Application.sln
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Application", "Application\Application.csproj", "{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86
Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Debug|x86.ActiveCfg = Debug|x86
{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Debug|x86.Build.0 = Debug|x86
{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Debug|x64.ActiveCfg = Debug|x64
{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Debug|x64.Build.0 = Debug|x64
{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Release|Any CPU.Build.0 = Release|Any CPU
{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Release|x86.ActiveCfg = Release|x86
{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Release|x86.Build.0 = Release|x86
{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Release|x64.ActiveCfg = Release|x64
{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
我所知道的和我尝试过的
microsofts docs 显示您可以使用元标记 <DependentUpon>
,我尝试过但没有成功。
文档还提到 conditions 在 .csproj
中使用的其他软件,这让我觉得一旦我有了一个有效的配置,我就可以创造一个条件让它适用于两个平台。
tasks 似乎可以解决此特定问题的另一件事是,但这感觉非常蛮力,我不知道如何为所有外部本地 DLL 解析 .csproj
移动。
this post 对解释如何 link 内容很有帮助。
<ItemGroup>
<Content Include="..\Shared\SharedSettings.json" Link="SharedSettings.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
通过使用 linked documentation in the question 中的条件,我能够分别移动 x86 和 x64 的 DLL。
这是 .csproj
的最终解决方案
<ItemGroup>
<Reference Include="AutoItX">
<HintPath>$(ProjectDir)\Lib\AutoItX\AutoItX3.Assembly.dll</HintPath>
</Reference>
<Content Include="$(ProjectDir)\Lib\AutoItX\AutoItX3_x64.dll" Condition="'$(Platform)' == 'x64'" Link="AutoItX3_x64.dll" CopyToOutputDirectory="PreserveNewest" />
<Content Include="$(ProjectDir)\Lib\AutoItX\AutoItX3.dll" Condition="'$(Platform)' == 'x86'" Link="AutoItX3.dll" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
设置
我将一个 C# VS2015 控制台应用程序项目转换为 VSCode,我正在尝试添加 DLL 引用并在构建时移动任何引用的 DLL。
开始时,Dotnet add package
没有工作,出现错误 The project does not support adding package references through the add package command.
,所以我手动将项目添加到 .csproj
文件中。我要添加的包是本地版本,位于./Lib/AutoItX
Lib/
└── AutoItX
├── AutoItX3_x64.dll
├── AutoItX3.Assembly.dll
├── AutoItX3.Assembly.xml
└── AutoItX3.dll
对 .csprog
<ItemGroup>
<Reference Include="AutoItX">
<HintPath>.\Lib\AutoItX\AutoItX3.Assembly.dll</HintPath>
</Reference>
</ItemGroup>
参考有效,如果我手动将 DLL 移动到 Debug 文件夹,它会找到它并且一切正常。
问题
有没有办法自动将 DLL 移动到文件夹中?
目前,在重新 运行 之后,我的调试文件夹如下所示:
bin/
└── x64
└── Debug
├── AutoItX3.Assembly.dll
├── AutoItX3.Assembly.xml
├── Application.exe
├── Application.exe.config
└── Application.pdb
我希望 AutoItX3_x64.dll
自动包含在 x64 构建中,如果可能的话,AutoIt3.dll
包含在 x86 构建中(它目前没有为 x86 构建设置,我只是想知道如何)
附加信息
我的launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "clr",
"request": "launch",
"preLaunchTask": "compile",
"program": "${workspaceFolder}/Application/bin/x64/Debug/StartApplication.exe",
"args": ["./Download/start.json"],
"cwd": "${workspaceFolder}",
"console": "externalTerminal",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "clr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
我的tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "compile",
"type": "shell",
"command": "dotnet",
"args": [
// Ask msbuild to generate full paths for file names.
"msbuild",
"Application.sln",
"/property:GenerateFullPaths=true",
"/property:Platform=x64"
],
"group": "build",
"presentation": {
// Reveal the output only if unrecognized errors occur.
"reveal": "silent"
},
// Use the standard MS compiler pattern to detect errors, warnings and infos
"problemMatcher": "$msCompile"
}
]
}
Application.sln
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Application", "Application\Application.csproj", "{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86
Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Debug|x86.ActiveCfg = Debug|x86
{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Debug|x86.Build.0 = Debug|x86
{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Debug|x64.ActiveCfg = Debug|x64
{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Debug|x64.Build.0 = Debug|x64
{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Release|Any CPU.Build.0 = Release|Any CPU
{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Release|x86.ActiveCfg = Release|x86
{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Release|x86.Build.0 = Release|x86
{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Release|x64.ActiveCfg = Release|x64
{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
我所知道的和我尝试过的
microsofts docs 显示您可以使用元标记 <DependentUpon>
,我尝试过但没有成功。
文档还提到 conditions 在 .csproj
中使用的其他软件,这让我觉得一旦我有了一个有效的配置,我就可以创造一个条件让它适用于两个平台。
tasks 似乎可以解决此特定问题的另一件事是,但这感觉非常蛮力,我不知道如何为所有外部本地 DLL 解析 .csproj
移动。
this post 对解释如何 link 内容很有帮助。
<ItemGroup>
<Content Include="..\Shared\SharedSettings.json" Link="SharedSettings.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
通过使用 linked documentation in the question 中的条件,我能够分别移动 x86 和 x64 的 DLL。
这是 .csproj
<ItemGroup>
<Reference Include="AutoItX">
<HintPath>$(ProjectDir)\Lib\AutoItX\AutoItX3.Assembly.dll</HintPath>
</Reference>
<Content Include="$(ProjectDir)\Lib\AutoItX\AutoItX3_x64.dll" Condition="'$(Platform)' == 'x64'" Link="AutoItX3_x64.dll" CopyToOutputDirectory="PreserveNewest" />
<Content Include="$(ProjectDir)\Lib\AutoItX\AutoItX3.dll" Condition="'$(Platform)' == 'x86'" Link="AutoItX3.dll" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>