user19338: I want to generate a block with specific transaction via bitcoin-cli on regtest.
The "generate" command does not have the option. It collects transactions in mempool by the default rule.
I guess I can do it with some code change like the following way but I don't want to change it if possible.
TestChain100Setup::CreateAndProcessBlock(const std::vector<CMutableTransaction>& txns, const CScript& scriptPubKey)
{
    const CChainParams& chainparams = Params();
    std::unique_ptr<CBlockTemplate> pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey);
    CBlock& block = pblocktemplate->block;

    // Replace mempool-selected txns with just coinbase plus passed-in txns:
    block.vtx.resize(1);
    for (const CMutableTransaction& tx : txns)
        block.vtx.push_back(MakeTransactionRef(tx));

https://github.com/bitcoin/bitcoin/blob/v0.17.1/src/miner.cpp#L147
https://github.com/bitcoin/bitcoin/blob/v0.17.1/src/test/test_bitcoin.cpp#L155
https://bitcoincore.org/en/doc/0.17.0/rpc/generating/generate/

user60443: When you run generate, it mines a block with the transactions in the mempool:
generate nblocks ( maxtries )

Mine up to nblocks blocks immediately (before the RPC call returns) to an address in the wallet.

If you want those new coins to be mined to a specific address, you can use generatetoaddress
You can create transactions and submit them to the mempool either using the wallet RPC, e.g. sendtoaddress or using the rawtransactions RPC:
e.g. 

createrawtransaction
signrawtransaction
sendrawtransaction

sendrawtransaction will put the transaction in the mempool, which can then be included in the next block using generate

19338: <p>I want to generate a block with specific transaction via bitcoin-cli on regtest.</p>

<p>The "generate" command does not have the option. It collects transactions in mempool by the default rule.</p>

<p>I guess I can do it with some code change like the following way but I don't want to change it if possible.</p>

<pre><code>TestChain100Setup::CreateAndProcessBlock(const std::vector&lt;CMutableTransaction&gt;&amp; txns, const CScript&amp; scriptPubKey)
{
    const CChainParams&amp; chainparams = Params();
    std::unique_ptr&lt;CBlockTemplate&gt; pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey);
    CBlock&amp; block = pblocktemplate-&gt;block;

    // Replace mempool-selected txns with just coinbase plus passed-in txns:
    block.vtx.resize(1);
    for (const CMutableTransaction&amp; tx : txns)
        block.vtx.push_back(MakeTransactionRef(tx));
</code></pre>

<p><a href="https://github.com/bitcoin/bitcoin/blob/v0.17.1/src/miner.cpp#L147" rel="nofollow noreferrer">https://github.com/bitcoin/bitcoin/blob/v0.17.1/src/miner.cpp#L147</a>
<a href="https://github.com/bitcoin/bitcoin/blob/v0.17.1/src/test/test_bitcoin.cpp#L155" rel="nofollow noreferrer">https://github.com/bitcoin/bitcoin/blob/v0.17.1/src/test/test_bitcoin.cpp#L155</a>
<a href="https://bitcoincore.org/en/doc/0.17.0/rpc/generating/generate/" rel="nofollow noreferrer">https://bitcoincore.org/en/doc/0.17.0/rpc/generating/generate/</a></p>
 60443: <p>When you run <a href="https://bitcoincore.org/en/doc/0.17.0/rpc/generating/generate/" rel="nofollow noreferrer"><code>generate</code></a>, it mines a block with the transactions in the mempool:</p>

<pre><code>generate nblocks ( maxtries )

Mine up to nblocks blocks immediately (before the RPC call returns) to an address in the wallet.
</code></pre>

<p>If you want those new coins to be mined to a specific address, you can use <a href="https://bitcoincore.org/en/doc/0.17.0/rpc/generating/generatetoaddress/" rel="nofollow noreferrer"><code>generatetoaddress</code></a></p>

<p>You can create transactions and submit them to the mempool either using the wallet RPC, e.g. <a href="https://bitcoincore.org/en/doc/0.17.0/rpc/wallet/sendtoaddress/" rel="nofollow noreferrer"><code>sendtoaddress</code></a> or using the rawtransactions RPC:
e.g. </p>

<ol>
<li><a href="https://bitcoincore.org/en/doc/0.17.0/rpc/rawtransactions/createrawtransaction/" rel="nofollow noreferrer"><code>createrawtransaction</code></a></li>
<li><a href="https://bitcoincore.org/en/doc/0.17.0/rpc/rawtransactions/signrawtransaction/" rel="nofollow noreferrer"><code>signrawtransaction</code></a></li>
<li><a href="https://bitcoincore.org/en/doc/0.17.0/rpc/rawtransactions/sendrawtransaction/" rel="nofollow noreferrer"><code>sendrawtransaction</code></a></li>
</ol>

<p><code>sendrawtransaction</code> will put the transaction in the mempool, which can then be included in the next block using <code>generate</code></p>
